1 #if LV_BUILD_TEST
2 #include "../lvgl.h"
3
4 #include "unity/unity.h"
5 #include "lv_test_helpers.h"
6
7 static uint32_t buf[CANVAS_WIDTH_TO_STRIDE(100, 4) * 100 + LV_DRAW_BUF_ALIGN];
8 extern const uint8_t test_lottie_approve[];
9 extern const size_t test_lottie_approve_size;
10
11 /*Due to different floating point precision
12 *the rendered images are slightly different on different architectures
13 *So compare the screenshots only on AMD64*/
14 #ifdef NON_AMD64_BUILD
15 #undef TEST_ASSERT_EQUAL_SCREENSHOT
16 #define TEST_ASSERT_EQUAL_SCREENSHOT(path) (void) path
17 #endif
18
setUp(void)19 void setUp(void)
20 {
21
22 }
23
tearDown(void)24 void tearDown(void)
25 {
26 lv_obj_clean(lv_screen_active());
27 }
28
test_lottie_simple(void)29 void test_lottie_simple(void)
30 {
31 lv_obj_t * lottie = lv_lottie_create(lv_screen_active());
32 lv_lottie_set_buffer(lottie, 100, 100, lv_draw_buf_align(buf, LV_COLOR_FORMAT_ARGB8888));
33 lv_lottie_set_src_data(lottie, test_lottie_approve, test_lottie_approve_size);
34 lv_obj_center(lottie);
35
36 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/lottie_1.png");
37
38 /*Wait a little*/
39 lv_test_wait(200);
40 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/lottie_2.png");
41
42 /*Should be the last frame*/
43 lv_test_wait(750);
44 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/lottie_3.png");
45
46 /*Setting a source should reset the animation*/
47 lv_lottie_set_src_data(lottie, test_lottie_approve, test_lottie_approve_size);
48
49 /*Should reset automatically*/
50 lv_test_wait(200);
51 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/lottie_2.png");
52 }
53
test_lottie_load_from_file(void)54 void test_lottie_load_from_file(void)
55 {
56 lv_obj_t * lottie = lv_lottie_create(lv_screen_active());
57 lv_lottie_set_buffer(lottie, 100, 100, lv_draw_buf_align(buf, LV_COLOR_FORMAT_ARGB8888));
58 lv_lottie_set_src_file(lottie, "src/test_assets/test_lottie_approve.json");
59 lv_obj_center(lottie);
60 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/lottie_1.png");
61
62 /*Wait a little*/
63 lv_test_wait(200);
64 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/lottie_2.png");
65
66 /*Should be the last frame*/
67 lv_test_wait(750);
68 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/lottie_3.png");
69
70 /*Setting a source should reset the animation*/
71 lv_lottie_set_src_data(lottie, test_lottie_approve, test_lottie_approve_size);
72
73 /*Should reset automatically*/
74 lv_test_wait(200);
75 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/lottie_2.png");
76 }
77
test_lottie_missing_settings(void)78 void test_lottie_missing_settings(void)
79 {
80 uint32_t tmp_buf[CANVAS_WIDTH_TO_STRIDE(100, 4) * 100 + LV_DRAW_BUF_ALIGN];
81
82 lv_obj_t * lottie1 = lv_lottie_create(lv_screen_active());
83 lv_lottie_set_buffer(lottie1, 100, 100, lv_draw_buf_align(tmp_buf, LV_COLOR_FORMAT_ARGB8888));
84
85 /*Shouldn't crash without source*/
86 lv_timer_handler();
87
88 lv_obj_t * lottie2 = lv_lottie_create(lv_screen_active());
89 /*Set the source first*/
90 lv_lottie_set_src_data(lottie2, test_lottie_approve, test_lottie_approve_size);
91
92 /*Shouldn't crash without buffer*/
93 lv_timer_handler();
94
95 lv_lottie_set_buffer(lottie2, 100, 100, lv_draw_buf_align(buf, LV_COLOR_FORMAT_ARGB8888));
96
97 lv_obj_center(lottie2);
98 lv_test_wait(950);
99 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/lottie_3.png");
100 }
101
test_lottie_rescale(void)102 void test_lottie_rescale(void)
103 {
104 lv_obj_t * lottie = lv_lottie_create(lv_screen_active());
105 lv_lottie_set_buffer(lottie, 100, 100, lv_draw_buf_align(buf, LV_COLOR_FORMAT_ARGB8888));
106 lv_lottie_set_src_data(lottie, test_lottie_approve, test_lottie_approve_size);
107 lv_obj_center(lottie);
108
109 /*Wait a little*/
110 lv_test_wait(200);
111 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/lottie_2.png");
112
113 lv_lottie_set_buffer(lottie, 50, 50, lv_draw_buf_align(buf, LV_COLOR_FORMAT_ARGB8888));
114 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/lottie_2_small.png");
115
116 /*Should be the last frame*/
117 lv_test_wait(750);
118 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/lottie_3_small.png");
119 }
120
121
test_lottie_non_uniform_shape(void)122 void test_lottie_non_uniform_shape(void)
123 {
124 lv_obj_t * lottie = lv_lottie_create(lv_screen_active());
125 lv_lottie_set_buffer(lottie, 50, 200, lv_draw_buf_align(buf, LV_COLOR_FORMAT_ARGB8888));
126 lv_lottie_set_src_data(lottie, test_lottie_approve, test_lottie_approve_size);
127 lv_obj_center(lottie);
128
129 lv_test_wait(950);
130 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/lottie_4.png");
131 }
132
test_lottie_memory_leak(void)133 void test_lottie_memory_leak(void)
134 {
135 size_t mem_before = lv_test_get_free_mem();
136
137 uint32_t i;
138 for(i = 0; i < 32; i++) {
139 lv_obj_t * lottie = lv_lottie_create(lv_screen_active());
140 lv_lottie_set_buffer(lottie, 100, 100, lv_draw_buf_align(buf, LV_COLOR_FORMAT_ARGB8888));
141 lv_lottie_set_src_data(lottie, test_lottie_approve, test_lottie_approve_size);
142 lv_obj_center(lottie);
143 lv_test_wait(753 * i); /*Render a random frame*/
144 lv_timer_handler();
145 lv_obj_delete(lottie);
146 }
147 TEST_ASSERT_MEM_LEAK_LESS_THAN(mem_before, 16);
148 }
149
test_lottie_no_jump_when_visible_again(void)150 void test_lottie_no_jump_when_visible_again(void)
151 {
152 lv_obj_t * lottie = lv_lottie_create(lv_screen_active());
153 lv_lottie_set_buffer(lottie, 100, 100, lv_draw_buf_align(buf, LV_COLOR_FORMAT_ARGB8888));
154 lv_lottie_set_src_data(lottie, test_lottie_approve, test_lottie_approve_size);
155 lv_obj_center(lottie);
156
157 /*Wait a little*/
158 lv_test_wait(200);
159 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/lottie_2.png");
160
161 lv_obj_add_flag(lottie, LV_OBJ_FLAG_HIDDEN);
162 lv_test_wait(300);
163 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/lottie_1.png"); /*Empty screen*/
164
165 /*Should be on the same frame*/
166 lv_obj_clear_flag(lottie, LV_OBJ_FLAG_HIDDEN);
167 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/lottie_2.png");
168
169 lv_test_wait(750);
170 TEST_ASSERT_EQUAL_SCREENSHOT("widgets/lottie_3.png");
171
172 }
173
174 #endif
175