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/KeepAlivePduCreator.h"
|
|
|
|
#include "fsfw/cfdp/pdu/KeepAlivePduReader.h"
|
2021-12-03 15:37:49 +01:00
|
|
|
#include "fsfw/globalfunctions/arrayprinter.h"
|
|
|
|
|
2022-08-03 13:23:49 +02:00
|
|
|
TEST_CASE("Keep Alive 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> kaBuffer = {};
|
|
|
|
uint8_t* buffer = kaBuffer.data();
|
|
|
|
size_t sz = 0;
|
|
|
|
EntityId destId(WidthInBytes::TWO_BYTES, 2);
|
|
|
|
TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15);
|
|
|
|
EntityId sourceId(WidthInBytes::TWO_BYTES, 1);
|
2022-09-15 18:41:15 +02:00
|
|
|
PduConfig pduConf(sourceId, destId, TransmissionMode::ACKNOWLEDGED, seqNum);
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2023-07-19 13:44:52 +02:00
|
|
|
Fss progress(0x50);
|
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
|
|
|
KeepAlivePduCreator serializer(pduConf, progress);
|
2022-02-02 10:29:30 +01:00
|
|
|
result = serializer.serialize(&buffer, &sz, kaBuffer.size(), SerializeIF::Endianness::NETWORK);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(result == returnvalue::OK);
|
2022-09-15 18:41:15 +02:00
|
|
|
REQUIRE(kaBuffer[10] == cfdp::FileDirective::KEEP_ALIVE);
|
2022-02-02 10:29:30 +01:00
|
|
|
uint32_t fsRaw = 0;
|
|
|
|
result = SerializeAdapter::deSerialize(&fsRaw, kaBuffer.data() + 11, nullptr,
|
|
|
|
SerializeIF::Endianness::NETWORK);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(result == returnvalue::OK);
|
2022-02-02 10:29:30 +01:00
|
|
|
REQUIRE(fsRaw == 0x50);
|
|
|
|
REQUIRE(sz == 15);
|
|
|
|
REQUIRE(serializer.getWholePduSize() == 15);
|
|
|
|
REQUIRE(serializer.getPduDataFieldLen() == 5);
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
pduConf.largeFile = true;
|
|
|
|
serializer.updateDirectiveFieldLen();
|
|
|
|
buffer = kaBuffer.data();
|
|
|
|
sz = 0;
|
|
|
|
result = serializer.serialize(&buffer, &sz, kaBuffer.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() == 19);
|
|
|
|
REQUIRE(serializer.getPduDataFieldLen() == 9);
|
|
|
|
uint64_t fsRawLarge = 0;
|
|
|
|
result = SerializeAdapter::deSerialize(&fsRawLarge, kaBuffer.data() + 11, nullptr,
|
|
|
|
SerializeIF::Endianness::NETWORK);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(result == returnvalue::OK);
|
2022-02-02 10:29:30 +01:00
|
|
|
REQUIRE(fsRawLarge == 0x50);
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
for (size_t invalidMaxSz = 0; invalidMaxSz < sz; invalidMaxSz++) {
|
|
|
|
buffer = kaBuffer.data();
|
|
|
|
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
|
|
|
}
|
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
|
|
|
KeepAlivePduCreator serializer(pduConf, progress);
|
2022-02-02 10:29:30 +01:00
|
|
|
result = serializer.serialize(&buffer, &sz, kaBuffer.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-02-02 10:29:30 +01:00
|
|
|
// Set another file size
|
|
|
|
progress.setFileSize(200, false);
|
2022-09-14 19:48:11 +02:00
|
|
|
KeepAlivePduReader reader(kaBuffer.data(), kaBuffer.size(), progress);
|
2022-09-08 11:08:40 +02:00
|
|
|
result = reader.parseData();
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(result == returnvalue::OK);
|
2022-09-08 11:08:40 +02:00
|
|
|
auto& progRef = reader.getProgress();
|
2022-02-02 10:29:30 +01:00
|
|
|
// Should have been overwritten
|
|
|
|
REQUIRE(progRef.getSize() == 0x50);
|
2022-09-08 11:08:40 +02:00
|
|
|
sz = reader.getWholePduSize();
|
2021-12-03 15:37:49 +01:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
// invalid max size
|
|
|
|
for (size_t invalidMaxSz = 0; invalidMaxSz < sz; invalidMaxSz++) {
|
2022-09-08 11:08:40 +02:00
|
|
|
ReturnValue_t setResult = reader.setReadOnlyData(kaBuffer.data(), invalidMaxSz);
|
2022-08-22 16:21:41 +02:00
|
|
|
if (setResult == returnvalue::OK) {
|
2022-09-08 11:08:40 +02:00
|
|
|
result = reader.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
|
|
|
}
|