fsfw/unittests/cfdp/testReservedMsgCreator.cpp

50 lines
2.0 KiB
C++
Raw Permalink Normal View History

2023-07-25 13:58:22 +02:00
#include <array>
#include <catch2/catch_test_macros.hpp>
#include "fsfw/cfdp/VarLenFields.h"
#include "fsfw/cfdp/tlv/ReservedMessageCreator.h"
#include "fsfw/cfdp/tlv/StringLv.h"
TEST_CASE("Reserved Message Creator", "[cfdp][tlv]") {
using namespace cfdp;
using namespace returnvalue;
std::string srcFileName = "hello.txt";
std::string destFileName = "hello2.txt";
std::array<uint8_t, 64> buffer{};
uint8_t msgBuf[32]{};
EntityId entityId(cfdp::WidthInBytes::ONE_BYTE, 5);
uint8_t* msgBufPtr = msgBuf;
size_t serLen = 0;
cfdp::StringLv srcName(srcFileName);
cfdp::StringLv destName(destFileName);
CHECK(entityId.serializeAsLv(&msgBufPtr, &serLen, sizeof(msgBuf)) == OK);
CHECK(srcName.serialize(&msgBufPtr, &serLen, sizeof(msgBuf), SerializeIF::Endianness::NETWORK) ==
OK);
CHECK(destName.serialize(&msgBufPtr, &serLen, sizeof(msgBuf), SerializeIF::Endianness::NETWORK) ==
OK);
ReservedMessageCreator creator(static_cast<uint8_t>(ProxyOpMessageType::PUT_REQUEST), msgBuf,
serLen);
serLen = 0;
ReturnValue_t result = creator.serializeBe(buffer.data(), serLen, buffer.size());
CHECK(result == returnvalue::OK);
CHECK(buffer[0] == TlvType::MSG_TO_USER);
// 4 bytes "cfdp" header, 1 byte message type, entity ID LV, source name LV and dest name LV
CHECK(buffer[1] ==
5 + 1 + entityId.getSerializedSize() + 1 + srcFileName.size() + 1 + destFileName.size());
CHECK(buffer[2] == 'c');
CHECK(buffer[3] == 'f');
CHECK(buffer[4] == 'd');
CHECK(buffer[5] == 'p');
CHECK(buffer[6] == static_cast<uint8_t>(ProxyOpMessageType::PUT_REQUEST));
CHECK(buffer[7] == 1);
CHECK(buffer[8] == entityId.getValue());
CHECK(buffer[9] == srcFileName.size());
size_t currentIdx = 10;
CHECK(std::string(reinterpret_cast<const char*>(buffer.data()) + currentIdx,
srcFileName.size()) == srcFileName);
currentIdx += srcFileName.size() + 1;
CHECK(std::string(reinterpret_cast<const char*>(buffer.data()) + currentIdx,
destFileName.size()) == destFileName);
}