2022-08-09 15:09:43 +02:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
|
2022-08-09 19:00:47 +02:00
|
|
|
#include "mocks/cfdp/FaultHandlerMock.h"
|
2022-08-09 15:09:43 +02:00
|
|
|
|
|
|
|
TEST_CASE("CFDP Fault Handler", "[cfdp]") {
|
|
|
|
using namespace cfdp;
|
2022-08-09 19:00:47 +02:00
|
|
|
auto fhMock = FaultHandlerMock();
|
2022-09-15 18:41:15 +02:00
|
|
|
cfdp::FaultHandlerCode fhCode;
|
|
|
|
cfdp::TransactionId id;
|
2022-08-09 15:29:22 +02:00
|
|
|
|
2022-08-09 15:09:43 +02:00
|
|
|
SECTION("State") {
|
|
|
|
// Verify initial condition
|
|
|
|
CHECK(fhMock.getFaultHandler(ConditionCode::UNSUPPORTED_CHECKSUM_TYPE, fhCode));
|
2022-09-15 18:41:15 +02:00
|
|
|
CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR);
|
2022-08-09 15:09:43 +02:00
|
|
|
CHECK(fhMock.getFaultHandler(ConditionCode::POSITIVE_ACK_LIMIT_REACHED, fhCode));
|
2022-09-15 18:41:15 +02:00
|
|
|
CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR);
|
2022-08-09 15:09:43 +02:00
|
|
|
CHECK(fhMock.getFaultHandler(ConditionCode::KEEP_ALIVE_LIMIT_REACHED, fhCode));
|
2022-09-15 18:41:15 +02:00
|
|
|
CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR);
|
2022-08-09 15:09:43 +02:00
|
|
|
CHECK(fhMock.getFaultHandler(ConditionCode::INVALID_TRANSMISSION_MODE, fhCode));
|
2022-09-15 18:41:15 +02:00
|
|
|
CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR);
|
2022-08-09 15:09:43 +02:00
|
|
|
CHECK(fhMock.getFaultHandler(ConditionCode::FILESTORE_REJECTION, fhCode));
|
2022-09-15 18:41:15 +02:00
|
|
|
CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR);
|
2022-08-09 15:09:43 +02:00
|
|
|
CHECK(fhMock.getFaultHandler(ConditionCode::FILE_CHECKSUM_FAILURE, fhCode));
|
2022-09-15 18:41:15 +02:00
|
|
|
CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR);
|
2022-08-09 15:09:43 +02:00
|
|
|
CHECK(fhMock.getFaultHandler(ConditionCode::FILE_SIZE_ERROR, fhCode));
|
2022-09-15 18:41:15 +02:00
|
|
|
CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR);
|
2022-08-09 15:09:43 +02:00
|
|
|
CHECK(fhMock.getFaultHandler(ConditionCode::NAK_LIMIT_REACHED, fhCode));
|
2022-09-15 18:41:15 +02:00
|
|
|
CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR);
|
2022-08-09 15:09:43 +02:00
|
|
|
CHECK(fhMock.getFaultHandler(ConditionCode::INACTIVITY_DETECTED, fhCode));
|
2022-09-15 18:41:15 +02:00
|
|
|
CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR);
|
2022-08-09 15:09:43 +02:00
|
|
|
CHECK(fhMock.getFaultHandler(ConditionCode::CHECK_LIMIT_REACHED, fhCode));
|
2022-09-15 18:41:15 +02:00
|
|
|
CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR);
|
2022-08-09 15:09:43 +02:00
|
|
|
}
|
|
|
|
|
2022-08-09 15:29:22 +02:00
|
|
|
SECTION("Call Handler, Ignore Fault") {
|
2022-09-15 18:41:15 +02:00
|
|
|
auto& info = fhMock.getFhInfo(FaultHandlerCode::IGNORE_ERROR);
|
|
|
|
CHECK(fhMock.reportFault(id, ConditionCode::CHECK_LIMIT_REACHED));
|
2022-08-09 15:29:22 +02:00
|
|
|
CHECK(info.callCount == 1);
|
|
|
|
CHECK(info.condCodes.back() == ConditionCode::CHECK_LIMIT_REACHED);
|
2022-09-15 18:41:15 +02:00
|
|
|
fhMock.reportFault(id, ConditionCode::FILE_CHECKSUM_FAILURE);
|
2022-08-09 15:29:22 +02:00
|
|
|
CHECK(info.callCount == 2);
|
|
|
|
CHECK(info.condCodes.back() == ConditionCode::FILE_CHECKSUM_FAILURE);
|
|
|
|
}
|
|
|
|
|
2022-09-15 18:41:15 +02:00
|
|
|
SECTION("Invalid Reported Code") { CHECK(not fhMock.reportFault(id, ConditionCode::NO_ERROR)); }
|
2022-08-09 15:29:22 +02:00
|
|
|
|
2022-08-09 15:46:42 +02:00
|
|
|
SECTION("Invalid FH code") {
|
|
|
|
CHECK(not fhMock.setFaultHandler(ConditionCode::KEEP_ALIVE_LIMIT_REACHED,
|
2022-09-15 18:41:15 +02:00
|
|
|
FaultHandlerCode::RESERVED));
|
2022-08-09 15:46:42 +02:00
|
|
|
CHECK(fhMock.getFaultHandler(ConditionCode::KEEP_ALIVE_LIMIT_REACHED, fhCode));
|
2022-09-15 18:41:15 +02:00
|
|
|
CHECK(fhCode == FaultHandlerCode::IGNORE_ERROR);
|
|
|
|
CHECK(not fhMock.setFaultHandler(ConditionCode::NO_ERROR, FaultHandlerCode::IGNORE_ERROR));
|
2022-08-09 15:46:42 +02:00
|
|
|
CHECK(not fhMock.getFaultHandler(ConditionCode::NO_ERROR, fhCode));
|
2022-08-09 15:29:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Set Other Fault Handler") {
|
|
|
|
CHECK(fhMock.setFaultHandler(ConditionCode::FILE_CHECKSUM_FAILURE,
|
2022-09-15 18:41:15 +02:00
|
|
|
FaultHandlerCode::NOTICE_OF_CANCELLATION));
|
2022-08-09 15:29:22 +02:00
|
|
|
CHECK(fhMock.setFaultHandler(ConditionCode::INACTIVITY_DETECTED,
|
2022-09-15 18:41:15 +02:00
|
|
|
FaultHandlerCode::ABANDON_TRANSACTION));
|
2022-08-09 15:29:22 +02:00
|
|
|
CHECK(fhMock.setFaultHandler(ConditionCode::KEEP_ALIVE_LIMIT_REACHED,
|
2022-09-15 18:41:15 +02:00
|
|
|
FaultHandlerCode::NOTICE_OF_SUSPENSION));
|
|
|
|
auto& ignoreInfo = fhMock.getFhInfo(FaultHandlerCode::IGNORE_ERROR);
|
|
|
|
auto& cancellationInfo = fhMock.getFhInfo(FaultHandlerCode::NOTICE_OF_CANCELLATION);
|
|
|
|
auto& suspensionInfo = fhMock.getFhInfo(FaultHandlerCode::NOTICE_OF_SUSPENSION);
|
|
|
|
auto& abandonInfo = fhMock.getFhInfo(FaultHandlerCode::ABANDON_TRANSACTION);
|
2022-08-09 15:29:22 +02:00
|
|
|
|
2022-09-15 18:41:15 +02:00
|
|
|
CHECK(fhMock.reportFault(id, ConditionCode::FILE_CHECKSUM_FAILURE));
|
2022-08-09 15:29:22 +02:00
|
|
|
CHECK(cancellationInfo.callCount == 1);
|
|
|
|
CHECK(cancellationInfo.condCodes.back() == ConditionCode::FILE_CHECKSUM_FAILURE);
|
|
|
|
CHECK(ignoreInfo.callCount == 0);
|
|
|
|
CHECK(suspensionInfo.callCount == 0);
|
|
|
|
CHECK(abandonInfo.callCount == 0);
|
|
|
|
|
2022-09-15 18:41:15 +02:00
|
|
|
CHECK(fhMock.reportFault(id, ConditionCode::INACTIVITY_DETECTED));
|
2022-08-09 15:29:22 +02:00
|
|
|
CHECK(cancellationInfo.callCount == 1);
|
|
|
|
CHECK(ignoreInfo.callCount == 0);
|
|
|
|
CHECK(suspensionInfo.callCount == 0);
|
|
|
|
CHECK(abandonInfo.callCount == 1);
|
|
|
|
CHECK(abandonInfo.condCodes.back() == ConditionCode::INACTIVITY_DETECTED);
|
|
|
|
|
2022-09-15 18:41:15 +02:00
|
|
|
CHECK(fhMock.reportFault(id, ConditionCode::KEEP_ALIVE_LIMIT_REACHED));
|
2022-08-09 15:29:22 +02:00
|
|
|
CHECK(cancellationInfo.callCount == 1);
|
|
|
|
CHECK(ignoreInfo.callCount == 0);
|
|
|
|
CHECK(suspensionInfo.callCount == 1);
|
|
|
|
CHECK(suspensionInfo.condCodes.back() == ConditionCode::KEEP_ALIVE_LIMIT_REACHED);
|
|
|
|
CHECK(abandonInfo.callCount == 1);
|
2022-08-09 15:09:43 +02:00
|
|
|
}
|
|
|
|
}
|