2022-02-02 10:29:30 +01:00
|
|
|
#include <array>
|
2021-12-03 15:37:49 +01:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
|
2022-09-14 19:48:11 +02:00
|
|
|
#include "fsfw/cfdp/pdu/PromptPduCreator.h"
|
|
|
|
#include "fsfw/cfdp/pdu/PromptPduReader.h"
|
2021-12-03 15:37:49 +01:00
|
|
|
#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;
|
2022-08-16 01:08:26 +02:00
|
|
|
ReturnValue_t result = returnvalue::OK;
|
2022-02-02 10:29:30 +01:00
|
|
|
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") {
|
2022-09-14 19:48:11 +02:00
|
|
|
PromptPduCreator serializer(pduConf, cfdp::PromptResponseRequired::PROMPT_KEEP_ALIVE);
|
2022-02-02 10:29:30 +01:00
|
|
|
result = serializer.serialize(&buffer, &sz, rawBuf.size(), SerializeIF::Endianness::NETWORK);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(result == returnvalue::OK);
|
2022-02-02 10:29:30 +01:00
|
|
|
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);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(result != returnvalue::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);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(result != returnvalue::OK);
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
}
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
SECTION("Deserialize") {
|
2022-09-14 19:48:11 +02:00
|
|
|
PromptPduCreator serializer(pduConf, cfdp::PromptResponseRequired::PROMPT_KEEP_ALIVE);
|
2022-02-02 10:29:30 +01:00
|
|
|
result = serializer.serialize(&buffer, &sz, rawBuf.size(), SerializeIF::Endianness::NETWORK);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(result == returnvalue::OK);
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-09-14 19:48:11 +02:00
|
|
|
PromptPduReader deserializer(rawBuf.data(), rawBuf.size());
|
2022-02-02 10:29:30 +01:00
|
|
|
result = deserializer.parseData();
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(result == returnvalue::OK);
|
2022-02-02 10:29:30 +01:00
|
|
|
REQUIRE(deserializer.getPromptResponseRequired() ==
|
|
|
|
cfdp::PromptResponseRequired::PROMPT_KEEP_ALIVE);
|
|
|
|
sz = deserializer.getWholePduSize();
|
2022-08-03 16:00:48 +02:00
|
|
|
// Set invalid size
|
2022-02-02 10:29:30 +01:00
|
|
|
rawBuf[2] = 1;
|
|
|
|
result = deserializer.parseData();
|
2022-08-03 16:00:48 +02:00
|
|
|
size_t sz2 = deserializer.getWholePduSize();
|
2022-02-02 10:29:30 +01:00
|
|
|
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++) {
|
2022-09-08 11:08:40 +02:00
|
|
|
ReturnValue_t setResult = deserializer.setReadOnlyData(rawBuf.data(), invalidMaxSz);
|
2022-08-22 16:21:41 +02:00
|
|
|
if (setResult == returnvalue::OK) {
|
2022-08-08 18:36:10 +02:00
|
|
|
result = deserializer.parseData();
|
2022-08-22 16:21:41 +02:00
|
|
|
REQUIRE(result != returnvalue::OK);
|
2022-08-08 18:36:10 +02:00
|
|
|
}
|
2021-12-03 15:37:49 +01:00
|
|
|
}
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
2021-12-03 15:37:49 +01:00
|
|
|
}
|