fsfw/unittests/cfdp/handler/testSourceHandler.cpp

60 lines
2.3 KiB
C++
Raw Normal View History

2022-09-14 19:29:43 +02:00
#include <catch2/catch_test_macros.hpp>
2023-07-27 17:15:01 +02:00
#include <filesystem>
2022-09-14 19:29:43 +02:00
2023-07-17 11:37:20 +02:00
#include "fsfw/cfdp.h"
2023-07-27 17:15:01 +02:00
#include "fsfw/cfdp/handler/PutRequest.h"
2023-07-17 11:37:20 +02:00
#include "fsfw/cfdp/handler/SourceHandler.h"
#include "fsfw/cfdp/pdu/EofPduCreator.h"
#include "fsfw/cfdp/pdu/FileDataCreator.h"
#include "fsfw/cfdp/pdu/MetadataPduCreator.h"
#include "fsfw/util/SeqCountProvider.h"
2023-07-17 11:37:20 +02:00
#include "mocks/AcceptsTmMock.h"
#include "mocks/EventReportingProxyMock.h"
#include "mocks/FilesystemMock.h"
#include "mocks/MessageQueueMock.h"
#include "mocks/StorageManagerMock.h"
#include "mocks/cfdp/FaultHandlerMock.h"
#include "mocks/cfdp/RemoteConfigTableMock.h"
#include "mocks/cfdp/UserMock.h"
TEST_CASE("CFDP Source Handler", "[cfdp]") {
using namespace cfdp;
using namespace returnvalue;
2023-07-27 17:15:01 +02:00
using namespace std::filesystem;
2023-07-17 11:37:20 +02:00
MessageQueueId_t destQueueId = 2;
AcceptsTmMock tmReceiver(destQueueId);
MessageQueueMock mqMock(destQueueId);
EntityId localId = EntityId(UnsignedByteField<uint16_t>(2));
EntityId remoteId = EntityId(UnsignedByteField<uint16_t>(3));
FaultHandlerMock fhMock;
LocalEntityCfg localEntityCfg(localId, IndicationCfg(), fhMock);
FilesystemMock fsMock;
UserMock userMock(fsMock);
SeqCountProviderU16 seqCountProvider;
SourceHandlerParams dp(localEntityCfg, userMock, seqCountProvider);
2023-07-17 11:37:20 +02:00
EventReportingProxyMock eventReporterMock;
LocalPool::LocalPoolConfig storeCfg = {{10, 32}, {10, 64}, {10, 128}, {10, 1024}};
StorageManagerMock tcStore(2, storeCfg);
StorageManagerMock tmStore(3, storeCfg);
FsfwParams fp(tmReceiver, &mqMock, &eventReporterMock);
auto sourceHandler = SourceHandler(dp, fp);
2023-07-27 17:15:01 +02:00
SECTION("Test Basic") {
CHECK(sourceHandler.getState() == CfdpState::IDLE);
CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE);
}
SECTION("Transfer empty file") {
RemoteEntityCfg cfg;
EntityId id(cfdp::WidthInBytes::ONE_BYTE, 5);
cfg.remoteId = id;
FilesystemParams srcFileName("/tmp/cfdp-test.txt");
fsMock.createFile(srcFileName);
cfdp::StringLv srcNameLv(srcFileName.path, std::strlen(srcFileName.path));
FilesystemParams destFileName("/tmp/cfdp-test.txt");
cfdp::StringLv destNameLv(destFileName.path, std::strlen(destFileName.path));
PutRequest putRequest(id, srcNameLv, destNameLv);
CHECK(sourceHandler.transactionStart(putRequest, cfg) == OK);
}
2023-07-17 11:37:20 +02:00
}