2022-08-17 16:47:46 +02:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
|
|
|
|
#include "fsfw/serialize/SerializeIF.h"
|
2024-11-15 10:56:43 +01:00
|
|
|
#include "mock/FilesystemMock.h"
|
2022-08-17 16:47:46 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
TEST_CASE("Filesystem Mock", "[mocks]") {
|
|
|
|
auto fsMock = FilesystemMock();
|
|
|
|
|
|
|
|
SECTION("Create File") {
|
|
|
|
FilesystemParams params("hello.txt");
|
2024-05-24 14:29:42 +02:00
|
|
|
CHECK(fsMock.createFile("hello.txt") == returnvalue::OK);
|
2022-08-17 16:47:46 +02:00
|
|
|
auto iter = fsMock.fileMap.find("hello.txt");
|
|
|
|
REQUIRE(iter != fsMock.fileMap.end());
|
|
|
|
FilesystemMock::FileInfo &stats = iter->second;
|
|
|
|
CHECK(stats.fileSegQueue.empty());
|
|
|
|
CHECK(stats.fileRaw.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Write to File") {
|
|
|
|
std::string testData = "test data";
|
|
|
|
FileOpParams params("hello.txt", testData.size());
|
2024-05-24 14:29:42 +02:00
|
|
|
CHECK(fsMock.writeToFile("hello.txt", 0, reinterpret_cast<const uint8_t *>(testData.data()),
|
|
|
|
testData.size()) == returnvalue::OK);
|
2022-08-17 16:47:46 +02:00
|
|
|
auto iter = fsMock.fileMap.find("hello.txt");
|
|
|
|
REQUIRE(iter != fsMock.fileMap.end());
|
|
|
|
FilesystemMock::FileInfo &stats = iter->second;
|
|
|
|
CHECK(not stats.fileSegQueue.empty());
|
|
|
|
CHECK(not stats.fileRaw.empty());
|
|
|
|
auto &segment = stats.fileSegQueue.back();
|
|
|
|
CHECK(segment.offset == 0);
|
|
|
|
CHECK(std::string(reinterpret_cast<const char *>(segment.data.data()), segment.data.size()) ==
|
|
|
|
testData);
|
|
|
|
CHECK(std::string(reinterpret_cast<const char *>(stats.fileRaw.data()), segment.data.size()) ==
|
|
|
|
testData);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Create Directory") {
|
|
|
|
FilesystemParams params("hello");
|
2024-05-24 14:29:42 +02:00
|
|
|
CHECK(fsMock.createDirectory("hello") == returnvalue::OK);
|
2022-08-17 16:47:46 +02:00
|
|
|
REQUIRE(not fsMock.dirMap.empty());
|
|
|
|
auto iter = fsMock.dirMap.find("hello");
|
|
|
|
REQUIRE(iter != fsMock.dirMap.end());
|
|
|
|
auto &dirInfo = iter->second;
|
|
|
|
CHECK(dirInfo.createCallCount == 1);
|
|
|
|
CHECK(dirInfo.delCallCount == 0);
|
|
|
|
}
|
|
|
|
}
|