1 #if LV_BUILD_TEST
2 #include "../lvgl.h"
3 
4 #include "unity/unity.h"
5 
6 const char * read_exp =
7     "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam sed maximus orci. Morbi massa nisi, varius eu convallis ac, venenatis at metus. In in nibh id urna pretium feugiat vitae eu libero. Ut eget fringilla eros. Nunc ullamcorper lectus mauris, vel rhoncus velit volutpat et. Phasellus sed molestie massa. Maecenas quis dui sollicitudin, vulputate nunc ut, dictum quam. Nam a congue lorem. Nulla non facilisis sapien. Ut luctus nulla nibh, sed finibus urna porta non. Duis aliquet augue id urna euismod auctor. Integer pellentesque vulputate enim non mattis. Donec finibus mattis dolor, et feugiat nisi pharetra porta. Mauris ullamcorper cursus magna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.";
8 
setUp(void)9 void setUp(void)
10 {
11     /* Function run before every test */
12 }
13 
tearDown(void)14 void tearDown(void)
15 {
16     /* Function run after every test */
17 }
18 #include <stdio.h>
test_read(void)19 void test_read(void)
20 {
21     lv_fs_res_t res;
22 
23     /*'A' has cache*/
24     lv_fs_file_t fa;
25     res = lv_fs_open(&fa, "A:src/test_files/readtest.txt", LV_FS_MODE_RD);
26     TEST_ASSERT_EQUAL(LV_FS_RES_OK, res);
27 
28     /*'B' has no cache*/
29     lv_fs_file_t fb;
30     res = lv_fs_open(&fb, "B:src/test_files/readtest.txt", LV_FS_MODE_RD);
31     TEST_ASSERT_EQUAL(LV_FS_RES_OK, res);
32 
33     /*Use an odd size to make sure it's not aligned with the drivier's'cache size*/
34     uint8_t buf[79];
35     uint32_t cnt = 0;
36     uint32_t br = 1;
37     while(br) {
38         res = lv_fs_read(&fa, buf, sizeof(buf), &br);
39         TEST_ASSERT_EQUAL(LV_FS_RES_OK, res);
40         TEST_ASSERT_TRUE(memcmp(buf, read_exp + cnt, br) == 0);
41 
42         res = lv_fs_read(&fb, buf, sizeof(buf), &br);
43         TEST_ASSERT_EQUAL(LV_FS_RES_OK, res);
44         TEST_ASSERT_TRUE(memcmp(buf, read_exp + cnt, br) == 0);
45         cnt += br;
46     }
47 
48     lv_fs_close(&fa);
49     lv_fs_close(&fb);
50 }
51 
52 #endif
53