From 6930656d4e5bc52c429bfdd9669e052cf18aaec1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 17 Aug 2022 17:09:39 +0200 Subject: [PATCH] added some more basic tests --- src/fsfw/cfdp/handler/RemoteConfigTableIF.h | 2 +- unittests/cfdp/handler/testDestHandler.cpp | 7 ++++++- unittests/mocks/cfdp/RemoteConfigTableMock.cpp | 15 ++++++++++++--- unittests/mocks/cfdp/RemoteConfigTableMock.h | 7 ++++++- unittests/mocks/cfdp/UserMock.h | 2 +- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/fsfw/cfdp/handler/RemoteConfigTableIF.h b/src/fsfw/cfdp/handler/RemoteConfigTableIF.h index 767492d50..1cd1ec1d8 100644 --- a/src/fsfw/cfdp/handler/RemoteConfigTableIF.h +++ b/src/fsfw/cfdp/handler/RemoteConfigTableIF.h @@ -8,7 +8,7 @@ namespace cfdp { class RemoteConfigTableIF { public: virtual ~RemoteConfigTableIF() = default; - virtual bool getRemoteCfg(EntityId remoteId, RemoteEntityCfg* cfg) = 0; + virtual bool getRemoteCfg(const cfdp::EntityId& remoteId, cfdp::RemoteEntityCfg** cfg) = 0; }; } // namespace cfdp diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 0d9fe9f54..8189096dd 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -1,7 +1,9 @@ #include #include "fsfw/cfdp.h" +#include "mocks/FilesystemMock.h" #include "mocks/cfdp/FaultHandlerMock.h" +#include "mocks/cfdp/RemoteConfigTableMock.h" #include "mocks/cfdp/UserMock.h" TEST_CASE("CFDP Dest Handler", "[cfdp]") { @@ -9,7 +11,10 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { EntityId localId = EntityId(UnsignedByteField(2)); auto fhMock = FaultHandlerMock(); auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock); - // auto userMock = UserMock(); + auto fsMock = FilesystemMock(); + auto userMock = UserMock(fsMock); + auto remoteCfgTableMock = RemoteConfigTableMock(); + auto destHandler = DestHandler(localEntityCfg, userMock, remoteCfgTableMock); SECTION("State") {} } \ No newline at end of file diff --git a/unittests/mocks/cfdp/RemoteConfigTableMock.cpp b/unittests/mocks/cfdp/RemoteConfigTableMock.cpp index 83827a369..9cb0b77c1 100644 --- a/unittests/mocks/cfdp/RemoteConfigTableMock.cpp +++ b/unittests/mocks/cfdp/RemoteConfigTableMock.cpp @@ -1,6 +1,15 @@ #include "RemoteConfigTableMock.h" -bool cfdp::RemoteConfigTableMock::getRemoteCfg(cfdp::EntityId remoteId, - cfdp::RemoteEntityCfg *cfg) { - return false; +void cfdp::RemoteConfigTableMock::addRemoteConfig(const cfdp::RemoteEntityCfg& cfg) { + remoteCfgTable.emplace(cfg.remoteId, cfg); +} + +bool cfdp::RemoteConfigTableMock::getRemoteCfg(const cfdp::EntityId& remoteId, + cfdp::RemoteEntityCfg** cfg) { + auto iter = remoteCfgTable.find(remoteId); + if (iter == remoteCfgTable.end()) { + return false; + } + *cfg = &iter->second; + return true; } diff --git a/unittests/mocks/cfdp/RemoteConfigTableMock.h b/unittests/mocks/cfdp/RemoteConfigTableMock.h index e3e954e47..70891836c 100644 --- a/unittests/mocks/cfdp/RemoteConfigTableMock.h +++ b/unittests/mocks/cfdp/RemoteConfigTableMock.h @@ -1,13 +1,18 @@ #ifndef FSFW_TESTS_CFDP_REMOTCONFIGTABLEMOCK_H #define FSFW_TESTS_CFDP_REMOTCONFIGTABLEMOCK_H +#include + #include "fsfw/cfdp/handler/RemoteConfigTableIF.h" namespace cfdp { class RemoteConfigTableMock : public RemoteConfigTableIF { public: - bool getRemoteCfg(EntityId remoteId, RemoteEntityCfg *cfg) override; + void addRemoteConfig(const RemoteEntityCfg& cfg); + bool getRemoteCfg(const cfdp::EntityId& remoteId, cfdp::RemoteEntityCfg** cfg) override; + + std::map remoteCfgTable; }; } // namespace cfdp diff --git a/unittests/mocks/cfdp/UserMock.h b/unittests/mocks/cfdp/UserMock.h index 7106a844c..d9d05336f 100644 --- a/unittests/mocks/cfdp/UserMock.h +++ b/unittests/mocks/cfdp/UserMock.h @@ -5,9 +5,9 @@ namespace cfdp { class UserMock : public UserBase { + public: explicit UserMock(HasFileSystemIF& vfs); - public: void transactionIndication(TransactionId id) override; void eofSentIndication(TransactionId id) override; void abandonedIndication(TransactionId id, ConditionCode code, size_t progress) override;