Skip to content

Commit 7d7abdf

Browse files
author
Vincent Dupont
committed
squash spiffs unittests add dir tests
1 parent 8469eba commit 7d7abdf

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

tests/unittests/tests-spiffs/tests-spiffs.c

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static void tests_spiffs_write(void)
7474

7575
res = vfs_read(fd, r_buf, sizeof(r_buf));
7676
TEST_ASSERT(res == sizeof(buf));
77-
//TEST_ASSERT_EQUAL_STRING(buf, r_buf);
77+
TEST_ASSERT_EQUAL_STRING(&buf[0], &r_buf[0]);
7878
printf("read buf: %s\n", r_buf);
7979

8080
res = vfs_close(fd);
@@ -107,13 +107,85 @@ static void tests_spiffs_unlink(void)
107107
TEST_ASSERT(res >= 0);
108108
}
109109

110+
static void tests_spiffs_readdir(void)
111+
{
112+
const char buf0[] = "TESTSTRING";
113+
const char buf1[] = "TESTTESTSTRING";
114+
const char buf2[] = "TESTSTRINGSTRING";
115+
116+
int mp = vfs_mount(&spiffs_file_system, "/", &spiffs_desc);
117+
TEST_ASSERT(mp >= 0);
118+
119+
int fd0 = vfs_open("/test0.txt", O_CREAT | O_RDWR, 0);
120+
TEST_ASSERT(fd0 >= 0);
121+
122+
int fd1 = vfs_open("/test1.txt", O_CREAT | O_RDWR, 0);
123+
TEST_ASSERT(fd1 >= 0);
124+
125+
int fd2 = vfs_open("/a/test2.txt", O_CREAT | O_RDWR, 0);
126+
TEST_ASSERT(fd2 >= 0);
127+
128+
int res = vfs_write(fd0, buf0, sizeof(buf0));
129+
TEST_ASSERT(res == sizeof(buf0));
130+
131+
res = vfs_write(fd1, buf1, sizeof(buf1));
132+
TEST_ASSERT(res == sizeof(buf1));
133+
134+
res = vfs_write(fd2, buf2, sizeof(buf2));
135+
TEST_ASSERT(res == sizeof(buf2));
136+
137+
res = vfs_close(fd0);
138+
TEST_ASSERT(res == 0);
139+
140+
res = vfs_close(fd1);
141+
TEST_ASSERT(res == 0);
142+
143+
res = vfs_close(fd2);
144+
TEST_ASSERT(res == 0);
145+
146+
vfs_DIR dirp;
147+
res = vfs_opendir(&dirp, "/");
148+
149+
vfs_dirent_t entry;
150+
res = vfs_readdir(&dirp, &entry);
151+
TEST_ASSERT(res == 1);
152+
TEST_ASSERT_EQUAL_STRING("test0.txt", &(entry.d_name[0]));
153+
154+
res = vfs_readdir(&dirp, &entry);
155+
TEST_ASSERT(res == 1);
156+
TEST_ASSERT_EQUAL_STRING("test1.txt", &(entry.d_name[0]));
157+
158+
res = vfs_readdir(&dirp, &entry);
159+
TEST_ASSERT(res == 1);
160+
TEST_ASSERT_EQUAL_STRING("a/test2.txt", &(entry.d_name[0]));
161+
162+
res = vfs_readdir(&dirp, &entry);
163+
TEST_ASSERT(res == 0);
164+
165+
res = vfs_closedir(&dirp);
166+
TEST_ASSERT(res == 0);
167+
168+
res = vfs_unlink("/test0.txt");
169+
TEST_ASSERT(res == 0);
170+
171+
res = vfs_unlink("/test1.txt");
172+
TEST_ASSERT(res == 0);
173+
174+
res = vfs_unlink("/a/test2.txt");
175+
TEST_ASSERT(res == 0);
176+
177+
res = vfs_umount(mp);
178+
TEST_ASSERT(res >= 0);
179+
}
180+
110181
Test *tests_spiffs_tests(void)
111182
{
112183
EMB_UNIT_TESTFIXTURES(fixtures) {
113184
new_TestFixture(test_spiffs_mount_umount),
114185
new_TestFixture(tests_spiffs_open_close),
115186
new_TestFixture(tests_spiffs_write),
116187
new_TestFixture(tests_spiffs_unlink),
188+
new_TestFixture(tests_spiffs_readdir),
117189
};
118190

119191
EMB_UNIT_TESTCALLER(spiffs_tests, NULL, NULL, fixtures);

0 commit comments

Comments
 (0)