2022-02-02 10:29:30 +01:00
|
|
|
#include <array>
|
2021-12-03 15:37:49 +01:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
|
|
|
|
#include "fsfw/cfdp/pdu/PromptPduDeserializer.h"
|
|
|
|
#include "fsfw/cfdp/pdu/PromptPduSerializer.h"
|
|
|
|
#include "fsfw/globalfunctions/arrayprinter.h"
|
|
|
|
|
2022-08-03 13:23:49 +02:00
|
|
|
TEST_CASE("Prompt PDU", "[cfdp][pdu]") {
|
2022-02-02 10:29:30 +01:00
|
|
|
using namespace cfdp;
|
|
|
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
|
|
|
std::array<uint8_t, 256> rawBuf = {};
|
|
|
|
uint8_t* buffer = rawBuf.data();
|
|
|
|
size_t sz = 0;
|
|
|
|
EntityId destId(WidthInBytes::TWO_BYTES, 2);
|
|
|
|
TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15);
|
|
|
|
EntityId sourceId(WidthInBytes::TWO_BYTES, 1);
|
2022-08-03 13:15:49 +02:00
|
|
|
PduConfig pduConf(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum);
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
SECTION("Serialize") {
|
|
|
|
PromptPduSerializer serializer(pduConf, cfdp::PromptResponseRequired::PROMPT_KEEP_ALIVE);
|
|
|
|
result = serializer.serialize(&buffer, &sz, rawBuf.size(), SerializeIF::Endianness::NETWORK);
|
|
|
|
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
|
|
|
|
REQUIRE(serializer.getWholePduSize() == 12);
|
|
|
|
REQUIRE(sz == 12);
|
|
|
|
REQUIRE(serializer.getPduDataFieldLen() == 2);
|
|
|
|
REQUIRE(rawBuf[10] == FileDirectives::PROMPT);
|
2022-08-03 13:15:49 +02:00
|
|
|
REQUIRE(((rawBuf[sz - 1] >> 7) & 0x01) == cfdp::PromptResponseRequired::PROMPT_KEEP_ALIVE);
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
for (size_t invalidMaxSz = 0; invalidMaxSz < sz; invalidMaxSz++) {
|
|
|
|
uint8_t* buffer = rawBuf.data();
|
|
|
|
size_t sz = 0;
|
|
|
|
result = serializer.serialize(&buffer, &sz, invalidMaxSz, SerializeIF::Endianness::NETWORK);
|
|
|
|
REQUIRE(result != HasReturnvaluesIF::RETURN_OK);
|
2021-12-03 15:37:49 +01:00
|
|
|
}
|
2022-02-02 10:29:30 +01:00
|
|
|
for (size_t invalidSz = 1; invalidSz < sz; invalidSz++) {
|
|
|
|
size_t locSz = invalidSz;
|
|
|
|
uint8_t* buffer = rawBuf.data();
|
|
|
|
result = serializer.serialize(&buffer, &locSz, sz, SerializeIF::Endianness::NETWORK);
|
|
|
|
REQUIRE(result != HasReturnvaluesIF::RETURN_OK);
|
|
|
|
}
|
|
|
|
}
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
SECTION("Deserialize") {
|
|
|
|
PromptPduSerializer serializer(pduConf, cfdp::PromptResponseRequired::PROMPT_KEEP_ALIVE);
|
|
|
|
result = serializer.serialize(&buffer, &sz, rawBuf.size(), SerializeIF::Endianness::NETWORK);
|
|
|
|
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
PromptPduDeserializer deserializer(rawBuf.data(), rawBuf.size());
|
|
|
|
result = deserializer.parseData();
|
|
|
|
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
|
|
|
|
REQUIRE(deserializer.getPromptResponseRequired() ==
|
|
|
|
cfdp::PromptResponseRequired::PROMPT_KEEP_ALIVE);
|
|
|
|
sz = deserializer.getWholePduSize();
|
|
|
|
rawBuf[2] = 1;
|
|
|
|
result = deserializer.parseData();
|
|
|
|
REQUIRE(result == SerializeIF::STREAM_TOO_SHORT);
|
|
|
|
rawBuf[2] = 2;
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
for (size_t invalidMaxSz = 0; invalidMaxSz < sz; invalidMaxSz++) {
|
|
|
|
deserializer.setData(rawBuf.data(), invalidMaxSz);
|
|
|
|
result = deserializer.parseData();
|
|
|
|
REQUIRE(result != HasReturnvaluesIF::RETURN_OK);
|
2021-12-03 15:37:49 +01:00
|
|
|
}
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
2021-12-03 15:37:49 +01:00
|
|
|
}
|