Skip to content

Commit

Permalink
squash spiffs unitests: add rename test
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Dupont committed Jul 13, 2016
1 parent 8832bad commit e0c8be4
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion tests/unittests/tests-spiffs/tests-spiffs.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,16 @@ 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[0], &r_buf[0]);
printf("read buf: %s\n", r_buf);

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

fd = vfs_open("/test.txt", O_RDONLY, 0);
TEST_ASSERT(fd >= 0);

res = vfs_read(fd, r_buf, sizeof(r_buf));
TEST_ASSERT(res == sizeof(buf));
TEST_ASSERT_EQUAL_STRING(&buf[0], &r_buf[0]);

res = vfs_close(fd);
TEST_ASSERT(res == 0);
Expand Down Expand Up @@ -178,6 +187,56 @@ static void tests_spiffs_readdir(void)
TEST_ASSERT(res >= 0);
}

static void tests_spiffs_rename(void)
{
const char buf[] = "TESTSTRING";
char r_buf[2 * sizeof(buf)];

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

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

int res = vfs_write(fd, buf, sizeof(buf));
TEST_ASSERT(res == sizeof(buf));

res = vfs_lseek(fd, 0, SEEK_SET);
TEST_ASSERT(res == 0);

res = vfs_read(fd, r_buf, sizeof(r_buf));
TEST_ASSERT(res == sizeof(buf));
TEST_ASSERT_EQUAL_STRING(&buf[0], &r_buf[0]);

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

res = vfs_rename("/test.txt", "/test1.txt");
TEST_ASSERT(res == 0);

fd = vfs_open("/test.txt", O_RDONLY, 0);
TEST_ASSERT(fd < 0);

fd = vfs_open("/test1.txt", O_RDONLY, 0);
TEST_ASSERT(fd >= 0);

res = vfs_lseek(fd, 0, SEEK_SET);
TEST_ASSERT(res == 0);

res = vfs_read(fd, r_buf, sizeof(r_buf));
TEST_ASSERT(res == sizeof(buf));
TEST_ASSERT_EQUAL_STRING(&buf[0], &r_buf[0]);

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

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

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

Test *tests_spiffs_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
Expand All @@ -186,6 +245,7 @@ Test *tests_spiffs_tests(void)
new_TestFixture(tests_spiffs_write),
new_TestFixture(tests_spiffs_unlink),
new_TestFixture(tests_spiffs_readdir),
new_TestFixture(tests_spiffs_rename),
};

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

0 comments on commit e0c8be4

Please sign in to comment.