Skip to content

Commit

Permalink
squash spiffs unittests add dir tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Dupont committed Jul 13, 2016
1 parent 8469eba commit 7d7abdf
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion tests/unittests/tests-spiffs/tests-spiffs.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static void tests_spiffs_write(void)

res = vfs_read(fd, r_buf, sizeof(r_buf));
TEST_ASSERT(res == sizeof(buf));
//TEST_ASSERT_EQUAL_STRING(buf, r_buf);
TEST_ASSERT_EQUAL_STRING(&buf[0], &r_buf[0]);
printf("read buf: %s\n", r_buf);

res = vfs_close(fd);
Expand Down Expand Up @@ -107,13 +107,85 @@ static void tests_spiffs_unlink(void)
TEST_ASSERT(res >= 0);
}

static void tests_spiffs_readdir(void)
{
const char buf0[] = "TESTSTRING";
const char buf1[] = "TESTTESTSTRING";
const char buf2[] = "TESTSTRINGSTRING";

int mp = vfs_mount(&spiffs_file_system, "/", &spiffs_desc);
TEST_ASSERT(mp >= 0);

int fd0 = vfs_open("/test0.txt", O_CREAT | O_RDWR, 0);
TEST_ASSERT(fd0 >= 0);

int fd1 = vfs_open("/test1.txt", O_CREAT | O_RDWR, 0);
TEST_ASSERT(fd1 >= 0);

int fd2 = vfs_open("/a/test2.txt", O_CREAT | O_RDWR, 0);
TEST_ASSERT(fd2 >= 0);

int res = vfs_write(fd0, buf0, sizeof(buf0));
TEST_ASSERT(res == sizeof(buf0));

res = vfs_write(fd1, buf1, sizeof(buf1));
TEST_ASSERT(res == sizeof(buf1));

res = vfs_write(fd2, buf2, sizeof(buf2));
TEST_ASSERT(res == sizeof(buf2));

res = vfs_close(fd0);
TEST_ASSERT(res == 0);

res = vfs_close(fd1);
TEST_ASSERT(res == 0);

res = vfs_close(fd2);
TEST_ASSERT(res == 0);

vfs_DIR dirp;
res = vfs_opendir(&dirp, "/");

vfs_dirent_t entry;
res = vfs_readdir(&dirp, &entry);
TEST_ASSERT(res == 1);
TEST_ASSERT_EQUAL_STRING("test0.txt", &(entry.d_name[0]));

res = vfs_readdir(&dirp, &entry);
TEST_ASSERT(res == 1);
TEST_ASSERT_EQUAL_STRING("test1.txt", &(entry.d_name[0]));

res = vfs_readdir(&dirp, &entry);
TEST_ASSERT(res == 1);
TEST_ASSERT_EQUAL_STRING("a/test2.txt", &(entry.d_name[0]));

res = vfs_readdir(&dirp, &entry);
TEST_ASSERT(res == 0);

res = vfs_closedir(&dirp);
TEST_ASSERT(res == 0);

res = vfs_unlink("/test0.txt");
TEST_ASSERT(res == 0);

res = vfs_unlink("/test1.txt");
TEST_ASSERT(res == 0);

res = vfs_unlink("/a/test2.txt");
TEST_ASSERT(res == 0);

res = vfs_umount(mp);
TEST_ASSERT(res >= 0);
}

Test *tests_spiffs_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_spiffs_mount_umount),
new_TestFixture(tests_spiffs_open_close),
new_TestFixture(tests_spiffs_write),
new_TestFixture(tests_spiffs_unlink),
new_TestFixture(tests_spiffs_readdir),
};

EMB_UNIT_TESTCALLER(spiffs_tests, NULL, NULL, fixtures);
Expand Down

0 comments on commit 7d7abdf

Please sign in to comment.