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 
obj_create(lv_obj_t * parent,lv_color_t color)19 lv_obj_t * obj_create(lv_obj_t * parent, lv_color_t color)
20 {
21     lv_obj_t * obj = lv_obj_create(parent);
22     lv_obj_set_style_bg_color(obj, color, LV_PART_MAIN);
23     lv_obj_set_width(obj, 150);
24     lv_obj_set_height(obj, 150);
25 
26     return obj;
27 }
28 
obj_set_margin(lv_obj_t * obj,int32_t left,int32_t top,int32_t right,int32_t bottom)29 void obj_set_margin(lv_obj_t * obj, int32_t left, int32_t top, int32_t right, int32_t bottom)
30 {
31     lv_obj_set_style_margin_left(obj, left, LV_PART_MAIN);
32     lv_obj_set_style_margin_top(obj, top, LV_PART_MAIN);
33     lv_obj_set_style_margin_right(obj, right, LV_PART_MAIN);
34     lv_obj_set_style_margin_bottom(obj, bottom, LV_PART_MAIN);
35 }
36 
test_flex(void)37 void test_flex(void)
38 {
39 #define N 5
40     lv_obj_t * obj0 = active_screen;
41 
42     lv_obj_set_flex_flow(obj0, LV_FLEX_FLOW_ROW);
43     lv_obj_set_style_pad_all(obj0, 0, LV_PART_MAIN);
44     lv_obj_set_style_pad_gap(obj0, 0, LV_PART_MAIN);
45     lv_obj_set_style_border_width(obj0, 0, LV_PART_MAIN);
46 
47     lv_obj_t * obj0s[N] = {
48         obj_create(obj0, lv_palette_main(LV_PALETTE_BLUE)),
49         obj_create(obj0, lv_palette_main(LV_PALETTE_RED)),
50         obj_create(obj0, lv_palette_main(LV_PALETTE_PURPLE)),
51         obj_create(obj0, lv_palette_main(LV_PALETTE_GREEN)),
52         obj_create(obj0, lv_palette_main(LV_PALETTE_PINK))
53     };
54 
55     lv_obj_t * o;
56     for(int i = 0; i < N; i++) {
57         o = obj0s[i];
58         lv_obj_set_style_radius(o, 0, LV_PART_MAIN);
59         lv_obj_set_scrollbar_mode(o, LV_SCROLLBAR_MODE_OFF);
60         lv_obj_set_style_border_width(o, 0, LV_PART_MAIN);
61     }
62 
63     lv_obj_set_width(obj0s[0], LV_PCT(50));
64     lv_obj_set_height(obj0s[0], LV_PCT(50));
65 
66     obj_set_margin(obj0s[0], 50, 3, 10, 50);
67     obj_set_margin(obj0s[1], 25, 6, 20, 50);
68     obj_set_margin(obj0s[2], 12, 12, 30, 50);
69     obj_set_margin(obj0s[3], 12, 25, 30, 50);
70     obj_set_margin(obj0s[4], 24, 50, 50, 50);
71 
72     lv_obj_update_layout(obj0);
73 
74     TEST_ASSERT_EQUAL_SCREENSHOT("margin_flex_0.png");
75 
76     lv_obj_set_flex_flow(obj0, LV_FLEX_FLOW_ROW_WRAP);
77     TEST_ASSERT_EQUAL_SCREENSHOT("margin_flex_1.png");
78 
79     lv_obj_set_style_flex_main_place(obj0, LV_FLEX_ALIGN_CENTER, LV_PART_MAIN);
80     TEST_ASSERT_EQUAL_SCREENSHOT("margin_flex_2.png");
81 
82     lv_obj_set_style_flex_cross_place(obj0, LV_FLEX_ALIGN_CENTER, LV_PART_MAIN);
83     TEST_ASSERT_EQUAL_SCREENSHOT("margin_flex_3.png");
84 
85     lv_obj_set_style_flex_track_place(obj0, LV_FLEX_ALIGN_CENTER, LV_PART_MAIN);
86     TEST_ASSERT_EQUAL_SCREENSHOT("margin_flex_4.png");
87 
88     lv_obj_set_flex_flow(obj0, LV_FLEX_FLOW_COLUMN_WRAP);
89     TEST_ASSERT_EQUAL_SCREENSHOT("margin_flex_5.png");
90 
91 #undef N
92 }
93 
94 #endif
95