1 #if LV_BUILD_TEST
2 #include "../lvgl.h"
3 
4 #include "unity/unity.h"
5 #include <unistd.h>
6 
obj_set_height_helper(void * obj,int32_t height)7 static void obj_set_height_helper(void * obj, int32_t height)
8 {
9     lv_obj_set_height((lv_obj_t *)obj, (lv_coord_t)height);
10 }
11 
test_gradient_vertical_misalignment(void)12 void test_gradient_vertical_misalignment(void)
13 {
14     lv_obj_t * obj = lv_obj_create(lv_scr_act());
15     lv_obj_set_style_bg_grad_dir(obj, LV_GRAD_DIR_VER, 0);
16     lv_obj_set_style_bg_grad_color(obj, lv_color_hex(0xff0000), 0);
17     lv_obj_set_style_bg_color(obj, lv_color_hex(0x00ff00), 0);
18 
19     lv_obj_set_size(obj, 300, 100);
20 
21     lv_refr_now(NULL);
22     lv_obj_set_style_bg_grad_color(obj, lv_color_hex(0xffff00), 0);
23     lv_obj_set_style_bg_color(obj, lv_color_hex(0x00ffff), 0);
24 
25     lv_anim_t a;
26     lv_anim_init(&a);
27     lv_anim_set_var(&a, obj);
28     lv_anim_set_exec_cb(&a, obj_set_height_helper);
29     lv_anim_set_time(&a, 3000);
30     lv_anim_set_playback_time(&a, 3000);
31     lv_anim_set_repeat_count(&a, 100);
32     lv_anim_set_values(&a, 0, 300);
33     lv_anim_start(&a);
34 
35     uint32_t i;
36     for(i = 0; i < 1000; i++) {
37         lv_timer_handler();
38         lv_tick_inc(100);
39         usleep(1000);
40     }
41 }
42 
test_custom_prop_ids(void)43 void test_custom_prop_ids(void)
44 {
45     uint8_t fake_flag = 0;
46     uint32_t initial_custom_props = lv_style_get_num_custom_props();
47     uint32_t max_props_to_register = 64;
48     for(uint32_t i = 0; i < max_props_to_register; i++) {
49         lv_style_prop_t prop = lv_style_register_prop(fake_flag);
50         /* Should have a higher index than the last built-in prop */
51         TEST_ASSERT_GREATER_THAN(_LV_STYLE_LAST_BUILT_IN_PROP, prop);
52         if(i == 0) {
53             /* Should be equal to the first expected index of a custom prop */
54             TEST_ASSERT_EQUAL(_LV_STYLE_NUM_BUILT_IN_PROPS + initial_custom_props, prop);
55         }
56         /*We should find our flags*/
57         TEST_ASSERT_EQUAL(fake_flag, _lv_style_prop_lookup_flags(prop));
58         if(fake_flag == 0xff)
59             fake_flag = 0;
60         else
61             fake_flag++;
62     }
63     TEST_ASSERT_EQUAL(initial_custom_props + max_props_to_register, lv_style_get_num_custom_props());
64     /*
65      * Check that the resizing algorithm works correctly, given that 64 props
66      * were registered + whatever's built-in. A failure here may just indicate
67      * that LVGL registers more built-in properties now and this needs adjustment.
68      */
69     extern uint32_t _lv_style_custom_prop_flag_lookup_table_size;
70     TEST_ASSERT_EQUAL(_lv_style_custom_prop_flag_lookup_table_size, 96);
71 }
72 
test_inherit_meta(void)73 void test_inherit_meta(void)
74 {
75     lv_obj_t * parent = lv_obj_create(lv_scr_act());
76     lv_obj_t * child = lv_obj_create(parent);
77     lv_obj_t * grandchild = lv_label_create(child);
78     lv_obj_set_style_text_color(parent, lv_color_hex(0xff0000), LV_PART_MAIN);
79     lv_obj_set_local_style_prop_meta(child, LV_STYLE_TEXT_COLOR, LV_STYLE_PROP_META_INHERIT, LV_PART_MAIN);
80     TEST_ASSERT_EQUAL_HEX(lv_color_hex(0xff0000).full, lv_obj_get_style_text_color(grandchild, LV_PART_MAIN).full);
81 }
82 
test_id_meta_overrun(void)83 void test_id_meta_overrun(void)
84 {
85     /* Test that property ID registration is blocked once the ID reaches into the meta bits */
86     lv_style_prop_t prop_id;
87     do {
88         prop_id = lv_style_register_prop(0);
89         if(prop_id != LV_STYLE_PROP_INV) {
90             TEST_ASSERT_EQUAL(0, prop_id & LV_STYLE_PROP_META_MASK);
91         }
92     } while(prop_id != LV_STYLE_PROP_INV);
93 }
94 
test_inherit_meta_with_lower_precedence_style(void)95 void test_inherit_meta_with_lower_precedence_style(void)
96 {
97     lv_obj_t * parent = lv_obj_create(lv_scr_act());
98     lv_obj_t * child = lv_obj_create(parent);
99     lv_obj_t * grandchild = lv_label_create(child);
100     lv_obj_set_style_text_color(parent, lv_color_hex(0xff0000), LV_PART_MAIN);
101     lv_style_t style;
102     lv_style_init(&style);
103     lv_style_set_text_color(&style, lv_color_hex(0xffffff));
104     lv_obj_set_local_style_prop_meta(child, LV_STYLE_TEXT_COLOR, LV_STYLE_PROP_META_INHERIT, LV_PART_MAIN);
105     lv_obj_add_style(child, &style, LV_PART_MAIN);
106     TEST_ASSERT_EQUAL_HEX(lv_color_hex(0xff0000).full, lv_obj_get_style_text_color(grandchild, LV_PART_MAIN).full);
107 }
108 
109 #endif
110