diff --git a/src/fsfw/cfdp/FaultHandlerBase.cpp b/src/fsfw/cfdp/FaultHandlerBase.cpp index 91c3afe4..443a1a92 100644 --- a/src/fsfw/cfdp/FaultHandlerBase.cpp +++ b/src/fsfw/cfdp/FaultHandlerBase.cpp @@ -23,7 +23,7 @@ bool FaultHandlerBase::setFaultHandler(cfdp::ConditionCode code, cfdp::FaultHand return true; } -bool FaultHandlerBase::faultCallback(cfdp::ConditionCode code) { +bool FaultHandlerBase::reportFault(cfdp::ConditionCode code) { if (not faultHandlerMap.contains(code)) { return false; } diff --git a/src/fsfw/cfdp/FaultHandlerBase.h b/src/fsfw/cfdp/FaultHandlerBase.h index 6a4abc8b..ba816161 100644 --- a/src/fsfw/cfdp/FaultHandlerBase.h +++ b/src/fsfw/cfdp/FaultHandlerBase.h @@ -25,7 +25,7 @@ class FaultHandlerBase { bool setFaultHandler(cfdp::ConditionCode code, cfdp::FaultHandlerCodes handler); - bool faultCallback(cfdp::ConditionCode code); + bool reportFault(cfdp::ConditionCode code); virtual void noticeOfSuspensionCb(cfdp::ConditionCode code) = 0; virtual void noticeOfCancellationCb(cfdp::ConditionCode code) = 0; @@ -33,7 +33,7 @@ class FaultHandlerBase { virtual void ignoreCb(cfdp::ConditionCode code) = 0; private: - etl::flat_map faultHandlerMap = { + etl::flat_map faultHandlerMap = { etl::pair{cfdp::ConditionCode::POSITIVE_ACK_LIMIT_REACHED, cfdp::FaultHandlerCodes::IGNORE_ERROR}, etl::pair{cfdp::ConditionCode::KEEP_ALIVE_LIMIT_REACHED, @@ -45,7 +45,9 @@ class FaultHandlerBase { etl::pair{cfdp::ConditionCode::NAK_LIMIT_REACHED, cfdp::FaultHandlerCodes::IGNORE_ERROR}, etl::pair{cfdp::ConditionCode::INACTIVITY_DETECTED, cfdp::FaultHandlerCodes::IGNORE_ERROR}, etl::pair{cfdp::ConditionCode::UNSUPPORTED_CHECKSUM_TYPE, - cfdp::FaultHandlerCodes::IGNORE_ERROR}}; + cfdp::FaultHandlerCodes::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::FILESTORE_REJECTION, cfdp::FaultHandlerCodes::IGNORE_ERROR}, + etl::pair{cfdp::ConditionCode::CHECK_LIMIT_REACHED, cfdp::FaultHandlerCodes::IGNORE_ERROR}}; }; } // namespace cfdp diff --git a/unittests/cfdp/CMakeLists.txt b/unittests/cfdp/CMakeLists.txt index 4a574af2..402381f4 100644 --- a/unittests/cfdp/CMakeLists.txt +++ b/unittests/cfdp/CMakeLists.txt @@ -1,5 +1,4 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE testCfdp.cpp testTlvsLvs.cpp - testSourceHandler.cpp) +target_sources(${FSFW_TEST_TGT} PRIVATE testCfdp.cpp testTlvsLvs.cpp) add_subdirectory(handler) add_subdirectory(pdu) diff --git a/unittests/cfdp/handler/CMakeLists.txt b/unittests/cfdp/handler/CMakeLists.txt index a209b995..f70e5dfb 100644 --- a/unittests/cfdp/handler/CMakeLists.txt +++ b/unittests/cfdp/handler/CMakeLists.txt @@ -1 +1,3 @@ -target_sources(${FSFW_TEST_TGT} PRIVATE testDistributor.cpp testDestHandler.cpp) +target_sources( + ${FSFW_TEST_TGT} PRIVATE testDistributor.cpp testDestHandler.cpp + testSourceHandler.cpp testFaultHandler.cpp) diff --git a/unittests/cfdp/handler/testFaultHandler.cpp b/unittests/cfdp/handler/testFaultHandler.cpp new file mode 100644 index 00000000..bea16889 --- /dev/null +++ b/unittests/cfdp/handler/testFaultHandler.cpp @@ -0,0 +1,36 @@ +#include + +#include "mocks/CfdpFaultHandlerMock.h" + +TEST_CASE("CFDP Fault Handler", "[cfdp]") { + using namespace cfdp; + auto fhMock = CfdpFaultHandlerMock(); + cfdp::FaultHandlerCodes fhCode; + SECTION("State") { + // Verify initial condition + CHECK(fhMock.getFaultHandler(ConditionCode::UNSUPPORTED_CHECKSUM_TYPE, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::POSITIVE_ACK_LIMIT_REACHED, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::KEEP_ALIVE_LIMIT_REACHED, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::INVALID_TRANSMISSION_MODE, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::FILESTORE_REJECTION, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::FILE_CHECKSUM_FAILURE, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::FILE_SIZE_ERROR, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::NAK_LIMIT_REACHED, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::INACTIVITY_DETECTED, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + CHECK(fhMock.getFaultHandler(ConditionCode::CHECK_LIMIT_REACHED, fhCode)); + CHECK(fhCode == FaultHandlerCodes::IGNORE_ERROR); + } + + SECTION("Call Handler") { + fhMock.reportFault(ConditionCode::CHECK_LIMIT_REACHED); + } +} \ No newline at end of file diff --git a/unittests/cfdp/testSourceHandler.cpp b/unittests/cfdp/handler/testSourceHandler.cpp similarity index 100% rename from unittests/cfdp/testSourceHandler.cpp rename to unittests/cfdp/handler/testSourceHandler.cpp diff --git a/unittests/cfdp/pdu/testFileDirective.cpp b/unittests/cfdp/pdu/testFileDirective.cpp index b694cd68..3dfaaa57 100644 --- a/unittests/cfdp/pdu/testFileDirective.cpp +++ b/unittests/cfdp/pdu/testFileDirective.cpp @@ -4,7 +4,7 @@ #include "fsfw/cfdp/pdu/FileDirectiveCreator.h" #include "fsfw/cfdp/pdu/FileDirectiveReader.h" -TEST_CASE("CFDP File Directive", "[cfdp]") { +TEST_CASE("CFDP File Directive", "[cfdp][pdu]") { using namespace cfdp; std::array serBuf{}; ReturnValue_t result; diff --git a/unittests/mocks/CfdpFaultHandlerMock.h b/unittests/mocks/CfdpFaultHandlerMock.h index 8003798e..ae7b251e 100644 --- a/unittests/mocks/CfdpFaultHandlerMock.h +++ b/unittests/mocks/CfdpFaultHandlerMock.h @@ -19,7 +19,7 @@ class CfdpFaultHandlerMock : public cfdp::FaultHandlerBase { void ignoreCb(cfdp::ConditionCode code) override; FaultInfo& getFhInfo(cfdp::FaultHandlerCodes fhCode); - bool faultCbWasCalled() const; + [[nodiscard]] bool faultCbWasCalled() const; void reset(); private: