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-02-02 10:29:30 +01:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include "fsfw/cfdp/FileSize.h"
|
2022-08-03 16:00:48 +02:00
|
|
|
#include "fsfw/cfdp/pdu/FileDirectiveCreator.h"
|
|
|
|
#include "fsfw/cfdp/pdu/FileDirectiveReader.h"
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/globalfunctions/arrayprinter.h"
|
2021-12-03 15:37:49 +01:00
|
|
|
#include "fsfw/serialize/SerializeAdapter.h"
|
|
|
|
|
2022-08-03 13:23:49 +02:00
|
|
|
TEST_CASE("CFDP Base", "[cfdp]") {
|
2022-02-02 10:29:30 +01:00
|
|
|
using namespace cfdp;
|
2022-08-03 13:15:49 +02:00
|
|
|
std::array<uint8_t, 32> serBuf{};
|
2022-08-03 13:23:49 +02:00
|
|
|
ReturnValue_t result;
|
2022-02-02 10:29:30 +01:00
|
|
|
cfdp::TransactionSeqNum seqNum = TransactionSeqNum(cfdp::WidthInBytes::ONE_BYTE, 2);
|
|
|
|
cfdp::EntityId sourceId = EntityId(cfdp::WidthInBytes::ONE_BYTE, 0);
|
|
|
|
cfdp::EntityId destId = EntityId(cfdp::WidthInBytes::ONE_BYTE, 1);
|
|
|
|
PduConfig pduConf =
|
2022-08-03 13:15:49 +02:00
|
|
|
PduConfig(sourceId, destId, cfdp::TransmissionModes::ACKNOWLEDGED, seqNum, false);
|
2022-02-02 10:29:30 +01:00
|
|
|
uint8_t* serTarget = serBuf.data();
|
|
|
|
const uint8_t* deserTarget = serTarget;
|
|
|
|
size_t serSize = 0;
|
|
|
|
|
|
|
|
SECTION("File Directive") {
|
2022-08-03 16:00:48 +02:00
|
|
|
auto fdSer = FileDirectiveCreator(pduConf, FileDirectives::ACK, 4);
|
2022-02-02 10:29:30 +01:00
|
|
|
REQUIRE(fdSer.getSerializedSize() == 8);
|
|
|
|
serTarget = serBuf.data();
|
|
|
|
serSize = 0;
|
|
|
|
result = fdSer.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::NETWORK);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(result == returnvalue::OK);
|
2022-02-02 10:29:30 +01:00
|
|
|
// Only version bits are set
|
|
|
|
REQUIRE(serBuf[0] == 0b00100000);
|
|
|
|
// PDU data field length is 5 (4 + Directive code octet)
|
|
|
|
REQUIRE(serBuf[1] == 0);
|
|
|
|
REQUIRE(serBuf[2] == 5);
|
|
|
|
// Entity and Transaction Sequence number are 1 byte large
|
|
|
|
REQUIRE(serBuf[3] == 0b00010001);
|
|
|
|
// Source ID
|
|
|
|
REQUIRE(serBuf[4] == 0);
|
|
|
|
// Transaction Seq Number
|
|
|
|
REQUIRE(serBuf[5] == 2);
|
|
|
|
// Dest ID
|
|
|
|
REQUIRE(serBuf[6] == 1);
|
|
|
|
REQUIRE(serBuf[7] == FileDirectives::ACK);
|
|
|
|
|
|
|
|
serTarget = serBuf.data();
|
|
|
|
size_t deserSize = 20;
|
|
|
|
serSize = 0;
|
|
|
|
REQUIRE(fdSer.deSerialize(&deserTarget, &deserSize, SerializeIF::Endianness::NETWORK) ==
|
2022-08-16 01:08:26 +02:00
|
|
|
returnvalue::FAILED);
|
2022-02-02 10:29:30 +01:00
|
|
|
REQUIRE(fdSer.serialize(nullptr, nullptr, 85, SerializeIF::Endianness::NETWORK) ==
|
2022-08-16 01:08:26 +02:00
|
|
|
returnvalue::FAILED);
|
2022-02-02 10:29:30 +01:00
|
|
|
for (uint8_t idx = 0; idx < 8; idx++) {
|
|
|
|
serTarget = serBuf.data();
|
|
|
|
serSize = 0;
|
|
|
|
REQUIRE(fdSer.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::NETWORK) ==
|
|
|
|
SerializeIF::BUFFER_TOO_SHORT);
|
2021-12-03 15:37:49 +01:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
deserTarget = serBuf.data();
|
|
|
|
deserSize = 0;
|
2022-08-03 16:00:48 +02:00
|
|
|
auto fdDeser = FileDirectiveReader(deserTarget, serBuf.size());
|
2022-02-02 10:29:30 +01:00
|
|
|
REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::NETWORK);
|
|
|
|
fdDeser.setEndianness(SerializeIF::Endianness::MACHINE);
|
|
|
|
REQUIRE(fdDeser.getEndianness() == SerializeIF::Endianness::MACHINE);
|
|
|
|
fdDeser.setEndianness(SerializeIF::Endianness::NETWORK);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(fdDeser.parseData() == returnvalue::OK);
|
2022-02-02 10:29:30 +01:00
|
|
|
REQUIRE(fdDeser.getFileDirective() == FileDirectives::ACK);
|
|
|
|
REQUIRE(fdDeser.getPduDataFieldLen() == 5);
|
|
|
|
REQUIRE(fdDeser.getHeaderSize() == 8);
|
2022-09-08 11:26:17 +02:00
|
|
|
REQUIRE(fdDeser.getPduType() == cfdp::PduTypes::FILE_DIRECTIVE);
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
serBuf[7] = 0xff;
|
|
|
|
// Invalid file directive
|
2022-09-08 11:53:06 +02:00
|
|
|
REQUIRE(fdDeser.parseData() == cfdp::INVALID_DIRECTIVE_FIELD);
|
2022-02-02 10:29:30 +01:00
|
|
|
}
|
|
|
|
|
2022-08-03 13:34:49 +02:00
|
|
|
SECTION("File Size") {
|
2022-02-02 10:29:30 +01:00
|
|
|
std::array<uint8_t, 8> fssBuf = {};
|
|
|
|
uint8_t* buffer = fssBuf.data();
|
|
|
|
size_t size = 0;
|
|
|
|
cfdp::FileSize fss;
|
|
|
|
REQUIRE(fss.getSize() == 0);
|
|
|
|
fss.setFileSize(0x20, false);
|
2022-08-03 13:15:49 +02:00
|
|
|
result = fss.serialize(&buffer, &size, fssBuf.size(), SerializeIF::Endianness::MACHINE);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(result == returnvalue::OK);
|
2022-02-02 10:29:30 +01:00
|
|
|
uint32_t fileSize = 0;
|
|
|
|
result = SerializeAdapter::deSerialize(&fileSize, fssBuf.data(), nullptr,
|
|
|
|
SerializeIF::Endianness::MACHINE);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(result == returnvalue::OK);
|
2022-02-02 10:29:30 +01:00
|
|
|
REQUIRE(fileSize == 0x20);
|
|
|
|
}
|
2022-08-03 13:34:49 +02:00
|
|
|
|
|
|
|
SECTION("Var Length Field") {
|
|
|
|
VarLenField defaultField;
|
|
|
|
CHECK(defaultField.getValue() == 0);
|
|
|
|
CHECK(defaultField.getWidth() == WidthInBytes::ONE_BYTE);
|
|
|
|
VarLenField explicitField(WidthInBytes::FOUR_BYTES, 12);
|
|
|
|
CHECK(explicitField.getWidth() == WidthInBytes::FOUR_BYTES);
|
|
|
|
CHECK(explicitField.getValue() == 12);
|
|
|
|
VarLenField fromUnsignedByteField(UnsignedByteField<uint16_t>(12));
|
|
|
|
CHECK(fromUnsignedByteField.getWidth() == WidthInBytes::TWO_BYTES);
|
|
|
|
CHECK(fromUnsignedByteField.getValue() == 12);
|
|
|
|
}
|
2021-12-03 15:37:49 +01:00
|
|
|
}
|