1 /**
2  * @file lv_test_style.c
3  *
4  */
5 
6 /*********************
7  *      INCLUDES
8  *********************/
9 #include "../../lvgl.h"
10 #include "../lv_test_assert.h"
11 #include "lv_test_style.h"
12 
13 #if LV_BUILD_TEST
14 
15 /*********************
16  *      DEFINES
17  *********************/
18 
19 /**********************
20  *      TYPEDEFS
21  **********************/
22 
23 /**********************
24  *  STATIC PROTOTYPES
25  **********************/
26 static void empty_style(void);
27 static void add_remove_read_prop(void);
28 static void cascade(void);
29 static void copy(void);
30 static void states(void);
31 static void mem_leak(void);
32 
33 /**********************
34  *  STATIC VARIABLES
35  **********************/
36 
37 /**********************
38  *      MACROS
39  **********************/
40 
41 /**********************
42  *   GLOBAL FUNCTIONS
43  **********************/
44 
lv_test_style(void)45 void lv_test_style(void)
46 {
47     lv_test_print("");
48     lv_test_print("====================");
49     lv_test_print("Start lv_style tests");
50     lv_test_print("====================");
51 
52     empty_style();
53     add_remove_read_prop();
54     cascade();
55     copy();
56     states();
57     mem_leak();
58 }
59 
60 
61 /**********************
62  *   STATIC FUNCTIONS
63  **********************/
64 
empty_style(void)65 static void empty_style(void)
66 {
67     lv_test_print("");
68     lv_test_print("Test empty styles:");
69     lv_test_print("-----------------");
70 
71     lv_style_list_t style_list;
72     lv_style_list_init(&style_list);
73 
74     lv_res_t found;
75     lv_style_int_t value;
76     lv_opa_t opa;
77     const void * ptr;
78     lv_color_t color;
79 
80     lv_test_print("Get a properties from an empty style");
81 
82     found = _lv_style_list_get_int(&style_list, LV_STYLE_TEXT_LINE_SPACE, &value);
83     lv_test_assert_int_eq(LV_RES_INV, found, "Get an 'int' property");
84 
85     found = _lv_style_list_get_opa(&style_list, LV_STYLE_BG_OPA, &opa);
86     lv_test_assert_int_eq(LV_RES_INV, found, "Get an 'opa' property");
87 
88     found = _lv_style_list_get_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr);
89     lv_test_assert_int_eq(LV_RES_INV, found, "Get a 'ptr' property");
90 
91     found = _lv_style_list_get_color(&style_list, LV_STYLE_BG_COLOR, &color);
92     lv_test_assert_int_eq(LV_RES_INV, found, "Get a 'color' property");
93 }
94 
add_remove_read_prop(void)95 static void add_remove_read_prop(void)
96 {
97     lv_test_print("");
98     lv_test_print("Add, remove and read properties:");
99     lv_test_print("--------------------------------");
100 
101     lv_style_list_t style_list;
102     lv_style_list_init(&style_list);
103 
104     lv_style_t style;
105     lv_style_init(&style);
106 
107     _lv_style_list_add_style(&style_list, &style);
108 
109     lv_res_t found;
110     lv_style_int_t value;
111     lv_opa_t opa;
112     const void * ptr;
113     lv_color_t color;
114 
115     lv_test_print("Add an empty style and read properties");
116 
117     found = _lv_style_list_get_int(&style_list, LV_STYLE_TEXT_LINE_SPACE, &value);
118     lv_test_assert_int_eq(LV_RES_INV, found, "Get a non existing 'int' property");
119 
120     found = _lv_style_list_get_opa(&style_list, LV_STYLE_BG_OPA, &opa);
121     lv_test_assert_int_eq(LV_RES_INV, found, "Get a non existing 'opa' property");
122 
123     found = _lv_style_list_get_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr);
124     lv_test_assert_int_eq(LV_RES_INV, found, "Get a non existing 'ptr' property");
125 
126     found = _lv_style_list_get_color(&style_list, LV_STYLE_BG_COLOR, &color);
127     lv_test_assert_int_eq(LV_RES_INV, found, "Get a non existing 'color' property");
128 
129     lv_test_print("Set properties and read back the values");
130     _lv_style_set_int(&style, LV_STYLE_TEXT_LINE_SPACE, 5);
131     _lv_style_set_opa(&style, LV_STYLE_BG_OPA, LV_OPA_50);
132     _lv_style_set_ptr(&style, LV_STYLE_TEXT_FONT, LV_THEME_DEFAULT_FONT_NORMAL);
133     _lv_style_set_color(&style, LV_STYLE_BG_COLOR, LV_COLOR_RED);
134 
135     found = _lv_style_list_get_int(&style_list, LV_STYLE_TEXT_LINE_SPACE, &value);
136     lv_test_assert_int_eq(LV_RES_OK, found, "Get an existing 'int' property");
137     lv_test_assert_int_eq(5, value, "Get the value of an 'int' property");
138 
139     found = _lv_style_list_get_opa(&style_list, LV_STYLE_BG_OPA, &opa);
140     lv_test_assert_int_eq(LV_RES_OK, found, "Get an existing 'opa' property");
141     lv_test_assert_int_eq(LV_OPA_50, opa, "Get the value of an  'opa' property");
142 
143     found = _lv_style_list_get_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr);
144     lv_test_assert_int_eq(LV_RES_OK, found, "Get an existing 'ptr' property");
145     lv_test_assert_ptr_eq(LV_THEME_DEFAULT_FONT_NORMAL, ptr, "Get the value of a 'ptr' property");
146 
147     found = _lv_style_list_get_color(&style_list, LV_STYLE_BG_COLOR, &color);
148     lv_test_assert_int_eq(LV_RES_OK, found, "Get an existing 'color' property");
149     lv_test_assert_color_eq(LV_COLOR_RED, color, "Get the value of a 'color' property");
150 
151     lv_test_print("Reset the the style");
152     lv_style_reset(&style);
153     found = _lv_style_list_get_int(&style_list, LV_STYLE_TEXT_LINE_SPACE, &value);
154     lv_test_assert_int_eq(LV_RES_INV, found, "Get an 'int' property from a reseted style");
155 
156     found = _lv_style_list_get_opa(&style_list, LV_STYLE_BG_OPA, &opa);
157     lv_test_assert_int_eq(LV_RES_INV, found, "Get an 'opa' property from a reseted style");
158 
159     found = _lv_style_list_get_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr);
160     lv_test_assert_int_eq(LV_RES_INV, found, "Get an 'ptr' property from a reseted style");
161 
162     found = _lv_style_list_get_color(&style_list, LV_STYLE_BG_COLOR, &color);
163     lv_test_assert_int_eq(LV_RES_INV, found, "Get an 'color' property from a reseted style");
164 
165     /*Clean-up*/
166     _lv_style_list_reset(&style_list);
167 }
168 
169 
cascade(void)170 static void cascade(void)
171 {
172     lv_test_print("");
173     lv_test_print("Cascade style styles:");
174     lv_test_print("----------------------");
175 
176     lv_style_list_t style_list;
177     lv_style_list_init(&style_list);
178 
179     lv_style_t style_first;
180     lv_style_init(&style_first);
181     _lv_style_list_add_style(&style_list, &style_first);
182 
183     lv_style_t style_second;
184     lv_style_init(&style_second);
185     _lv_style_list_add_style(&style_list, &style_second);
186 
187     lv_res_t found;
188     lv_style_int_t value;
189     lv_opa_t opa;
190     const void * ptr;
191     lv_color_t color;
192 
193     lv_test_print("Read properties set only in the firstly added style");
194 
195     _lv_style_set_int(&style_first, LV_STYLE_TEXT_LINE_SPACE, 5);
196     _lv_style_set_opa(&style_first, LV_STYLE_BG_OPA, LV_OPA_50);
197     _lv_style_set_ptr(&style_first, LV_STYLE_TEXT_FONT, LV_THEME_DEFAULT_FONT_NORMAL);
198     _lv_style_set_color(&style_first, LV_STYLE_BG_COLOR, LV_COLOR_RED);
199 
200     found = _lv_style_list_get_int(&style_list, LV_STYLE_TEXT_LINE_SPACE, &value);
201     lv_test_assert_int_eq(LV_RES_OK, found, "Get an 'int' property");
202     lv_test_assert_int_eq(5, value, "Get the value of an 'int' property");
203 
204     found = _lv_style_list_get_opa(&style_list, LV_STYLE_BG_OPA, &opa);
205     lv_test_assert_int_eq(LV_RES_OK, found, "Get an 'opa' property");
206     lv_test_assert_int_eq(LV_OPA_50, opa, "Get the value of an  'opa' property");
207 
208     found = _lv_style_list_get_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr);
209     lv_test_assert_int_eq(LV_RES_OK, found, "Get an 'ptr' property");
210     lv_test_assert_ptr_eq(LV_THEME_DEFAULT_FONT_NORMAL, ptr, "Get the value of a 'ptr' property");
211 
212     found = _lv_style_list_get_color(&style_list, LV_STYLE_BG_COLOR, &color);
213     lv_test_assert_int_eq(LV_RES_OK, found, "Get an 'color' property");
214     lv_test_assert_color_eq(LV_COLOR_RED, color, "Get the value of a 'color' property");
215 
216     lv_test_print("Overwrite the properties from the second style");
217 
218     _lv_style_set_int(&style_second, LV_STYLE_TEXT_LINE_SPACE, 10);
219     _lv_style_set_opa(&style_second, LV_STYLE_BG_OPA, LV_OPA_60);
220     _lv_style_set_ptr(&style_second, LV_STYLE_TEXT_FONT, LV_THEME_DEFAULT_FONT_NORMAL + 1);
221     _lv_style_set_color(&style_second, LV_STYLE_BG_COLOR, LV_COLOR_BLUE);
222 
223     found = _lv_style_list_get_int(&style_list, LV_STYLE_TEXT_LINE_SPACE, &value);
224     lv_test_assert_int_eq(LV_RES_OK, found, "Get an overwritten 'int' property");
225     lv_test_assert_int_eq(10, value, "Get the value of an overwritten 'int' property");
226 
227     found = _lv_style_list_get_opa(&style_list, LV_STYLE_BG_OPA, &opa);
228     lv_test_assert_int_eq(LV_RES_OK, found, "Get an overwritten 'opa' property");
229     lv_test_assert_int_eq(LV_OPA_60, opa, "Get the value of an overwritten 'opa' property");
230 
231     found = _lv_style_list_get_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr);
232     lv_test_assert_int_eq(LV_RES_OK, found, "Get an overwritten 'ptr' property");
233     lv_test_assert_ptr_eq(LV_THEME_DEFAULT_FONT_NORMAL + 1, ptr, "Get the value of an overwritten 'ptr' property");
234 
235     found = _lv_style_list_get_color(&style_list, LV_STYLE_BG_COLOR, &color);
236     lv_test_assert_int_eq(LV_RES_OK, found, "Get an overwritten 'color' property");
237     lv_test_assert_color_eq(LV_COLOR_BLUE, color, "Get the value of an overwritten 'color' property");
238 
239 
240     lv_test_print("Overwrite the properties with the local style");
241     _lv_style_list_set_local_int(&style_list, LV_STYLE_TEXT_LINE_SPACE, 20);
242     _lv_style_list_set_local_opa(&style_list, LV_STYLE_BG_OPA, LV_OPA_70);
243     _lv_style_list_set_local_ptr(&style_list, LV_STYLE_TEXT_FONT, LV_THEME_DEFAULT_FONT_NORMAL + 2);
244     _lv_style_list_set_local_color(&style_list, LV_STYLE_BG_COLOR, LV_COLOR_LIME);
245 
246     found = _lv_style_list_get_int(&style_list, LV_STYLE_TEXT_LINE_SPACE, &value);
247     lv_test_assert_int_eq(LV_RES_OK, found, "Get a local 'int' property");
248     lv_test_assert_int_eq(20, value, "Get the value of a local 'int' property");
249 
250     found = _lv_style_list_get_opa(&style_list, LV_STYLE_BG_OPA, &opa);
251     lv_test_assert_int_eq(LV_RES_OK, found, "Get a local 'opa' property");
252     lv_test_assert_int_eq(LV_OPA_70, opa, "Get the value of a local 'opa' property");
253 
254     found = _lv_style_list_get_ptr(&style_list, LV_STYLE_TEXT_FONT, &ptr);
255     lv_test_assert_int_eq(LV_RES_OK, found, "Get a local 'ptr' property");
256     lv_test_assert_ptr_eq(LV_THEME_DEFAULT_FONT_NORMAL + 2, ptr, "Get the value of a local'ptr' property");
257 
258     found = _lv_style_list_get_color(&style_list, LV_STYLE_BG_COLOR, &color);
259     lv_test_assert_int_eq(LV_RES_OK, found, "Get a local 'color' property");
260     lv_test_assert_color_eq(LV_COLOR_LIME, color, "Get the value of a local'color' property");
261 
262 
263     /*Clean-up*/
264     _lv_style_list_reset(&style_list);
265 }
266 
copy(void)267 static void copy(void)
268 {
269     lv_test_print("");
270     lv_test_print("Copy styles and style lists");
271     lv_test_print("---------------------------");
272 
273 
274     lv_test_print("Copy a style");
275     lv_style_t style_src;
276     lv_style_init(&style_src);
277     _lv_style_set_int(&style_src, LV_STYLE_TEXT_LINE_SPACE, 5);
278 
279     lv_style_t style_dest;
280     lv_style_init(&style_dest);
281     lv_style_copy(&style_dest, &style_src);
282 
283     int16_t weight;
284     lv_style_int_t value;
285 
286     weight = _lv_style_get_int(&style_dest, LV_STYLE_TEXT_LINE_SPACE, &value);
287     lv_test_assert_int_eq(0, weight, "Get a copied property from a style");
288     lv_test_assert_int_eq(5, value, "Get the value of a copied from a property");
289 
290     lv_test_print("Copy a style list");
291     lv_style_list_t list_src;
292     lv_style_list_init(&list_src);
293     _lv_style_list_add_style(&list_src, &style_src);
294     _lv_style_list_set_local_int(&list_src, LV_STYLE_LINE_DASH_WIDTH, 20);
295 
296     lv_style_list_t list_dest;
297     lv_style_list_init(&list_dest);
298     lv_style_list_copy(&list_dest, &list_src);
299 
300     lv_res_t found;
301     found = _lv_style_list_get_int(&list_dest, LV_STYLE_TEXT_LINE_SPACE, &value);
302     lv_test_assert_int_eq(LV_RES_OK, found, "Get a copied property from a list");
303     lv_test_assert_int_eq(5, value, "Get the value of a copied property from a list");
304     found = _lv_style_list_get_int(&list_dest, LV_STYLE_LINE_DASH_WIDTH, &value);
305     lv_test_assert_int_eq(LV_RES_OK, found, "Get a copied local property from a list");
306     lv_test_assert_int_eq(20, value, "Get the value of a copied local property from a list");
307 
308     /*Clean up*/
309     _lv_style_list_reset(&list_dest);
310     _lv_style_list_reset(&list_src);
311 
312     lv_style_reset(&style_dest);
313     lv_style_reset(&style_src);
314 }
315 
states(void)316 static void states(void)
317 {
318     lv_test_print("");
319     lv_test_print("Test style states:");
320     lv_test_print("------------------");
321 
322     lv_style_list_t style_list;
323     lv_style_list_init(&style_list);
324 
325     lv_style_t style_first;
326     lv_style_init(&style_first);
327     _lv_style_list_add_style(&style_list, &style_first);
328 
329     lv_style_t style_second;
330     lv_style_init(&style_second);
331     _lv_style_list_add_style(&style_list, &style_second);
332 
333     lv_test_print("Test state precedence in 1 style");
334     _lv_style_set_int(&style_first, LV_STYLE_TEXT_LINE_SPACE, 5);
335     _lv_style_set_int(&style_first, LV_STYLE_TEXT_LINE_SPACE | (LV_STATE_CHECKED) << LV_STYLE_STATE_POS, 6);
336     _lv_style_set_int(&style_first, LV_STYLE_TEXT_LINE_SPACE | (LV_STATE_PRESSED) << LV_STYLE_STATE_POS, 7);
337 
338     lv_res_t found;
339     lv_style_int_t value;
340 
341     found = _lv_style_list_get_int(&style_list, LV_STYLE_TEXT_LINE_SPACE, &value);
342     lv_test_assert_int_eq(LV_RES_OK, found, "Get an 'int' property in normal state");
343     lv_test_assert_int_eq(5, value, "Get the value of an 'int' property in normal state");
344 
345     found = _lv_style_list_get_int(&style_list, LV_STYLE_TEXT_LINE_SPACE | (LV_STATE_CHECKED) << LV_STYLE_STATE_POS, &value);
346     lv_test_assert_int_eq(LV_RES_OK, found, "Get an 'int' property in checked state");
347     lv_test_assert_int_eq(6, value, "Get the value of an 'int' in checked state");
348 
349     found = _lv_style_list_get_int(&style_list, LV_STYLE_TEXT_LINE_SPACE | (LV_STATE_PRESSED) << LV_STYLE_STATE_POS, &value);
350     lv_test_assert_int_eq(LV_RES_OK, found, "Get an 'int' property in pressed state");
351     lv_test_assert_int_eq(7, value, "Get the value of an 'int' in pressed state");
352 
353     found = _lv_style_list_get_int(&style_list, LV_STYLE_TEXT_LINE_SPACE | (LV_STATE_HOVERED) << LV_STYLE_STATE_POS, &value);
354     lv_test_assert_int_eq(LV_RES_OK, found, "Get an 'int' property in hover (unspecified) state");
355     lv_test_assert_int_eq(5, value, "Get the value of an 'int' in hover (unspecified) state");
356 
357     found = _lv_style_list_get_int(&style_list, LV_STYLE_TEXT_LINE_SPACE | (LV_STATE_CHECKED | LV_STATE_PRESSED | LV_STATE_HOVERED) << LV_STYLE_STATE_POS, &value);
358     lv_test_assert_int_eq(LV_RES_OK, found, "Get an 'int' property in checked pressed hovered state");
359     lv_test_assert_int_eq(7, value, "Get the value of an 'int' in checked pressed hovered state");
360 
361     lv_test_print("Test state precedence in 1 style with combined states");
362     _lv_style_set_opa(&style_first, LV_STYLE_BG_OPA, LV_OPA_50);
363     _lv_style_set_opa(&style_first, LV_STYLE_BG_OPA | (LV_STATE_CHECKED | LV_STATE_PRESSED) << LV_STYLE_STATE_POS, LV_OPA_60);
364 
365 
366     lv_opa_t opa;
367     found = _lv_style_list_get_opa(&style_list, LV_STYLE_BG_OPA , &opa);
368     lv_test_assert_int_eq(LV_RES_OK, found, "Get an 'opa' property in normal state");
369     lv_test_assert_int_eq(LV_OPA_50, opa, "Get the value of an 'int' in normal state");
370 
371     found = _lv_style_list_get_opa(&style_list, LV_STYLE_BG_OPA | (LV_STATE_CHECKED) << LV_STYLE_STATE_POS, &opa);
372     lv_test_assert_int_eq(LV_RES_OK, found, "Get an 'opa' property in checked (unspecified) state");
373     lv_test_assert_int_eq(LV_OPA_50, opa, "Get the value of an 'int' in checked (unspecified) state");
374 
375     found = _lv_style_list_get_opa(&style_list, LV_STYLE_BG_OPA | (LV_STATE_CHECKED | LV_STATE_PRESSED) << LV_STYLE_STATE_POS, &opa);
376     lv_test_assert_int_eq(LV_RES_OK, found, "Get an 'opa' property in checked pressed state");
377     lv_test_assert_int_eq(LV_OPA_60, opa, "Get the value of an 'int' in checked pressed state");
378 
379     found = _lv_style_list_get_opa(&style_list, LV_STYLE_BG_OPA | (LV_STATE_CHECKED | LV_STATE_PRESSED | LV_STATE_HOVERED) << LV_STYLE_STATE_POS, &opa);
380     lv_test_assert_int_eq(LV_RES_OK, found, "Get an 'opa' property in checked pressed hovered state");
381     lv_test_assert_int_eq(LV_OPA_60, opa, "Get the value of an 'int' in checked pressed hovered state");
382 
383 
384     lv_test_print("Test state precedence in 2 styles");
385     _lv_style_set_color(&style_first, LV_STYLE_BG_COLOR, LV_COLOR_YELLOW);
386     _lv_style_set_color(&style_first, LV_STYLE_BG_COLOR | (LV_STATE_HOVERED) << LV_STYLE_STATE_POS, LV_COLOR_RED);
387     _lv_style_set_color(&style_second, LV_STYLE_BG_COLOR | (LV_STATE_CHECKED) << LV_STYLE_STATE_POS, LV_COLOR_LIME);
388     _lv_style_set_color(&style_second, LV_STYLE_BG_COLOR | (LV_STATE_HOVERED | LV_STATE_PRESSED) << LV_STYLE_STATE_POS, LV_COLOR_BLUE);
389 
390     lv_color_t color;
391 
392     found = _lv_style_list_get_color(&style_list, LV_STYLE_BG_COLOR, &color);
393     lv_test_assert_int_eq(LV_RES_OK, found, "Get a 'color' property in normal state");
394     lv_test_assert_color_eq(LV_COLOR_YELLOW, color, "Get the value of a 'color' property in normal state");
395 
396     found = _lv_style_list_get_color(&style_list, LV_STYLE_BG_COLOR | (LV_STATE_HOVERED) << LV_STYLE_STATE_POS, &color);
397     lv_test_assert_int_eq(LV_RES_OK, found, "Get a 'color' property in hovered state");
398     lv_test_assert_color_eq(LV_COLOR_RED, color, "Get the value of a 'color' in hovered state");
399 
400     found = _lv_style_list_get_color(&style_list, LV_STYLE_BG_COLOR | (LV_STATE_CHECKED) << LV_STYLE_STATE_POS, &color);
401     lv_test_assert_int_eq(LV_RES_OK, found, "Get a 'color' property in checked state");
402     lv_test_assert_color_eq(LV_COLOR_LIME, color, "Get the value of a 'color' in checked state");
403 
404     found = _lv_style_list_get_color(&style_list, LV_STYLE_BG_COLOR | (LV_STATE_HOVERED | LV_STATE_PRESSED) << LV_STYLE_STATE_POS, &color);
405     lv_test_assert_int_eq(LV_RES_OK, found, "Get a 'color' property in hover pressed state");
406     lv_test_assert_color_eq(LV_COLOR_BLUE, color, "Get the value of a 'color' in hover pressed state");
407 
408     found = _lv_style_list_get_color(&style_list, LV_STYLE_BG_COLOR | (LV_STATE_EDITED) << LV_STYLE_STATE_POS, &color);
409     lv_test_assert_int_eq(LV_RES_OK, found, "Get a 'color' property in edit (unspecified) state");
410     lv_test_assert_color_eq(LV_COLOR_YELLOW, color, "Get the value of a 'color' in edit (unspecified) state");
411 
412     found = _lv_style_list_get_color(&style_list, LV_STYLE_BG_COLOR | (LV_STATE_CHECKED | LV_STATE_EDITED) << LV_STYLE_STATE_POS, &color);
413     lv_test_assert_int_eq(LV_RES_OK, found, "Get a 'color' property in checked edit state");
414     lv_test_assert_color_eq(LV_COLOR_LIME, color, "Get the value of a 'color' in checked edit state");
415 
416     /*Clean-up*/
417     _lv_style_list_reset(&style_list);
418 }
419 
420 
mem_leak(void)421 static void mem_leak(void)
422 {
423 
424     lv_test_print("");
425     lv_test_print("Test style  set, add, remove memory leak");
426     lv_test_print("----------------------------------------");
427 
428     lv_mem_monitor_t mon_start;
429     lv_mem_monitor_t mon_end;
430 
431     lv_style_list_t style_list;
432     lv_style_list_init(&style_list);
433 
434     lv_style_t style1;
435     lv_style_init(&style1);
436 
437     lv_style_t style2;
438     lv_style_init(&style2);
439 
440     lv_style_t style3;
441     lv_style_init(&style3);
442 
443     uint32_t i;
444 
445     lv_test_print("Set style properties");
446     lv_mem_monitor(&mon_start);
447     for(i = 0; i < 100; i++) {
448         _lv_style_set_color(&style2, LV_STYLE_LINE_COLOR, LV_COLOR_RED);
449 
450         _lv_style_set_color(&style3, LV_STYLE_LINE_COLOR, LV_COLOR_RED);
451         _lv_style_set_color(&style3, LV_STYLE_LINE_COLOR | (LV_STATE_EDITED) << LV_STYLE_STATE_POS, LV_COLOR_BLUE);
452         _lv_style_set_color(&style3, LV_STYLE_LINE_COLOR, LV_COLOR_BLUE);
453         _lv_style_set_color(&style3, LV_STYLE_LINE_COLOR | (LV_STATE_EDITED | LV_STATE_FOCUSED) << LV_STYLE_STATE_POS, LV_COLOR_GREEN);
454 
455         _lv_style_set_color(&style3, LV_STYLE_BG_COLOR, LV_COLOR_RED);
456 
457         _lv_style_set_color(&style3, LV_STYLE_IMAGE_RECOLOR, LV_COLOR_RED);
458 
459         lv_style_reset(&style1);
460         lv_style_reset(&style2);
461         lv_style_reset(&style3);
462 
463     }
464 
465     lv_test_assert_int_eq(LV_RES_OK, lv_mem_test(), "Memory integrity check");
466     lv_mem_defrag();
467     lv_mem_monitor(&mon_end);
468     lv_test_assert_int_lt(sizeof(void*) * 8, mon_start.free_size - mon_end.free_size, "Style memory leak");
469 
470     lv_test_print("Use local style");
471     lv_mem_monitor(&mon_start);
472     for(i = 0; i < 100; i++) {
473         _lv_style_list_set_local_ptr(&style_list, LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED) << LV_STYLE_STATE_POS, LV_THEME_DEFAULT_FONT_NORMAL);
474 
475         _lv_style_list_reset(&style_list);
476 
477         _lv_style_list_set_local_ptr(&style_list, LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED) << LV_STYLE_STATE_POS, NULL);
478         _lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK);
479         _lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK);
480         _lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK);
481         _lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK);
482         _lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK);
483         _lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK);
484 
485         _lv_style_list_reset(&style_list);
486     }
487 
488     _lv_style_list_reset(&style_list);
489     lv_test_assert_int_eq(LV_RES_OK, lv_mem_test(), "Memory integrity check");
490     lv_mem_defrag();
491     lv_mem_monitor(&mon_end);
492     lv_test_assert_int_lt(sizeof(void*) * 8, mon_start.free_size - mon_end.free_size, "Style memory leak");
493 
494 
495     lv_test_print("Add styles");
496     lv_mem_monitor(&mon_start);
497     for(i = 0; i < 100; i++) {
498         _lv_style_set_color(&style1, LV_STYLE_LINE_COLOR, LV_COLOR_RED);
499         _lv_style_set_color(&style2, LV_STYLE_LINE_COLOR, LV_COLOR_RED);
500         _lv_style_set_color(&style3, LV_STYLE_LINE_COLOR, LV_COLOR_RED);
501 
502         _lv_style_list_add_style(&style_list, &style1);
503         _lv_style_list_remove_style(&style_list, &style1);
504 
505         _lv_style_list_add_style(&style_list, &style2);
506         _lv_style_list_add_style(&style_list, &style3);
507 
508         _lv_style_list_remove_style(&style_list, &style2);
509         _lv_style_list_add_style(&style_list, &style1);
510 
511         _lv_style_list_reset(&style_list);
512         lv_style_reset(&style1);
513         lv_style_reset(&style2);
514         lv_style_reset(&style3);
515     }
516 
517     lv_test_assert_int_eq(LV_RES_OK, lv_mem_test(), "Memory integrity check");
518     lv_mem_defrag();
519     lv_mem_monitor(&mon_end);
520     lv_test_assert_int_lt(sizeof(void*) * 8, mon_start.free_size - mon_end.free_size, "Style memory leak");
521 
522     lv_test_print("Add styles and use local style");
523      lv_mem_monitor(&mon_start);
524      for(i = 0; i < 100; i++) {
525          _lv_style_set_color(&style1, LV_STYLE_LINE_COLOR, LV_COLOR_RED);
526          _lv_style_set_color(&style2, LV_STYLE_LINE_COLOR, LV_COLOR_RED);
527          _lv_style_set_color(&style3, LV_STYLE_LINE_COLOR, LV_COLOR_RED);
528 
529          if(i % 2 == 0) _lv_style_list_set_local_color(&style_list, LV_STYLE_LINE_COLOR, LV_COLOR_RED);
530 
531          _lv_style_list_add_style(&style_list, &style1);
532          _lv_style_list_remove_style(&style_list, &style1);
533 
534          _lv_style_list_add_style(&style_list, &style2);
535          _lv_style_list_add_style(&style_list, &style3);
536 
537          _lv_style_list_remove_style(&style_list, &style2);
538          _lv_style_list_add_style(&style_list, &style1);
539 
540 
541          if(i % 2 != 0) _lv_style_list_set_local_color(&style_list, LV_STYLE_LINE_COLOR, LV_COLOR_RED);
542 
543          _lv_style_list_reset(&style_list);
544          lv_style_reset(&style1);
545          lv_style_reset(&style2);
546          lv_style_reset(&style3);
547      }
548 
549      lv_test_assert_int_eq(LV_RES_OK, lv_mem_test(), "Memory integrity check");
550      lv_mem_defrag();
551      lv_mem_monitor(&mon_end);
552      lv_test_assert_int_lt(sizeof(void*) * 8, mon_start.free_size - mon_end.free_size, "Style memory leak");
553 
554 
555 
556     lv_test_print("Complex test");
557 
558     lv_mem_monitor(&mon_start);
559 
560     for(i = 0; i < 100; i++) {
561         if(i % 2 == 0) {
562             _lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_CLOSE);
563         }
564 
565         _lv_style_set_color(&style1, LV_STYLE_LINE_COLOR, LV_COLOR_RED);
566         _lv_style_set_color(&style1, LV_STYLE_LINE_COLOR | (LV_STATE_EDITED) << LV_STYLE_STATE_POS, LV_COLOR_BLUE);
567         _lv_style_set_color(&style1, LV_STYLE_LINE_COLOR, LV_COLOR_BLUE);
568         _lv_style_set_color(&style1, LV_STYLE_LINE_COLOR | (LV_STATE_EDITED | LV_STATE_FOCUSED) << LV_STYLE_STATE_POS, LV_COLOR_GREEN);
569 
570         _lv_style_list_add_style(&style_list, &style1);
571 
572 
573         if(i % 4 == 0) {
574             _lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_CLOSE);
575         }
576 
577         _lv_style_list_remove_style(&style_list, &style1);
578 
579         _lv_style_set_opa(&style2, LV_STYLE_TEXT_OPA, LV_OPA_10);
580         _lv_style_set_opa(&style2, LV_STYLE_TEXT_OPA, LV_OPA_20);
581         _lv_style_set_opa(&style2, LV_STYLE_TEXT_OPA, LV_OPA_30);
582         _lv_style_set_opa(&style2, LV_STYLE_TEXT_OPA, LV_OPA_40);
583         _lv_style_set_opa(&style2, LV_STYLE_TEXT_OPA, LV_OPA_50);
584         _lv_style_set_opa(&style2, LV_STYLE_TEXT_OPA, LV_OPA_60);
585 
586         _lv_style_list_add_style(&style_list, &style2);
587 
588         if(i % 8 == 0) {
589             _lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_CLOSE);
590         }
591 
592         _lv_style_list_add_style(&style_list, &style2);
593         _lv_style_list_add_style(&style_list, &style2);
594         _lv_style_list_add_style(&style_list, &style2);
595         _lv_style_list_add_style(&style_list, &style2);
596         _lv_style_list_remove_style(&style_list, &style2);
597 
598         _lv_style_set_int(&style3, LV_STYLE_PAD_LEFT, 10);
599         _lv_style_set_int(&style3, LV_STYLE_PAD_RIGHT, 20);
600         _lv_style_set_int(&style3, LV_STYLE_PAD_LEFT, 11);
601         _lv_style_set_int(&style3, LV_STYLE_PAD_RIGHT, 21);
602         _lv_style_set_int(&style3, LV_STYLE_PAD_LEFT, 12);
603         _lv_style_set_int(&style3, LV_STYLE_PAD_RIGHT, 22);
604         _lv_style_set_int(&style3, LV_STYLE_PAD_LEFT, 12);
605         _lv_style_set_int(&style3, LV_STYLE_PAD_RIGHT, 23);
606 
607         _lv_style_list_set_local_ptr(&style_list, LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED) << LV_STYLE_STATE_POS, LV_THEME_DEFAULT_FONT_NORMAL);
608         _lv_style_list_set_local_ptr(&style_list, LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED) << LV_STYLE_STATE_POS, NULL);
609         _lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK);
610         _lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK);
611         _lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK);
612         _lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK);
613         _lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK);
614         _lv_style_list_set_local_ptr(&style_list, LV_STYLE_PATTERN_IMAGE, LV_SYMBOL_OK);
615 
616         _lv_style_list_add_style(&style_list, &style3);
617         _lv_style_list_add_style(&style_list, &style2);
618         _lv_style_list_add_style(&style_list, &style1);
619 
620         _lv_style_list_reset(&style_list);
621         lv_style_reset(&style1);
622         lv_style_reset(&style2);
623         lv_style_reset(&style3);
624 
625     }
626 
627     _lv_style_list_reset(&style_list);
628     lv_style_reset(&style1);
629     lv_style_reset(&style2);
630     lv_style_reset(&style3);
631 
632     lv_test_assert_int_eq(LV_RES_OK, lv_mem_test(), "Memory integrity check");
633     lv_mem_defrag();
634     lv_mem_monitor(&mon_end);
635     lv_test_assert_int_lt(sizeof(void*) * 8, mon_start.free_size - mon_end.free_size, "Style memory leak");
636 }
637 #endif
638