Files
MuditaOS/module-vfs/tests/unittest.cpp
Radoslaw Wicik a8573a404c Apply new style
2020-03-17 10:03:16 +01:00

57 lines
1.3 KiB
C++

/*
* @file unittests_vfs.cpp
* @author Mateusz Piesta (mateusz.piesta@mudita.com)
* @date 17.05.19
* @brief
* @copyright Copyright (C) 2019 mudita.com
* @details
*/
#include "vfs.hpp"
#include "catch.hpp"
#include <stdint.h>
#include <algorithm>
#include <iostream>
class vfs vfs;
TEST_CASE("Test case 1")
{
vfs.Init();
const size_t testBufferSize = 1024 * 1024;
uint8_t testBuffer[testBufferSize] = {0};
auto fd = vfs.fopen("testFile.txt", "w");
REQUIRE(fd != nullptr);
auto bytesWritten = vfs.fwrite(testBuffer, 1, testBufferSize, fd);
REQUIRE(bytesWritten == testBufferSize);
auto currFilePos = vfs.ftell(fd);
REQUIRE(currFilePos == testBufferSize);
auto fileSize = vfs.filelength(fd);
REQUIRE(fileSize == testBufferSize);
currFilePos = vfs.ftell(fd);
REQUIRE(currFilePos == testBufferSize);
REQUIRE(vfs.fclose(fd) == 0);
auto cwd = vfs.getcurrdir();
auto path = cwd.substr(0, cwd.find_last_of("/\\"));
auto dirList = vfs.listdir((path + "/module-vfs/tests/test_dir").c_str());
REQUIRE(dirList.size() == 3);
REQUIRE(dirList[0].attributes == vfs::FileAttributes::Directory);
REQUIRE(dirList[0].fileName == "test_dir2");
REQUIRE(dirList[1].attributes == vfs::FileAttributes::Writable);
}