fsfw/unittests/cfdp/handler/testPutRequest.cpp

60 lines
2.7 KiB
C++
Raw Permalink Normal View History

2023-07-26 17:29:35 +02:00
#include <array>
#include <catch2/catch_test_macros.hpp>
2023-07-26 17:29:35 +02:00
#include "fsfw/cfdp/handler/PutRequest.h"
#include "fsfw/cfdp/tlv/ReservedMessageCreator.h"
TEST_CASE("Put Request", "[cfdp]") {
using namespace cfdp;
using namespace returnvalue;
std::array<uint8_t, 32> reservedMsgCustomData{};
std::array<uint8_t, 128> reservedMsgBuf{};
std::array<uint8_t, 128> buffer{};
EntityId destId(WidthInBytes::ONE_BYTE, 5);
std::string srcFileName = "hello.txt";
std::string destFileName = "hello2.txt";
uint8_t* msgBufPtr = reservedMsgCustomData.data();
size_t msgSize = 0;
cfdp::StringLv srcName(srcFileName);
cfdp::StringLv destName(destFileName);
CHECK(destId.serializeAsLv(&msgBufPtr, &msgSize, reservedMsgCustomData.size()) == OK);
CHECK(srcName.serialize(&msgBufPtr, &msgSize, reservedMsgCustomData.size(),
SerializeIF::Endianness::NETWORK) == OK);
CHECK(destName.serialize(&msgBufPtr, &msgSize, reservedMsgCustomData.size(),
SerializeIF::Endianness::NETWORK) == OK);
ReservedMessageCreator creator(static_cast<uint8_t>(ProxyOpMessageType::PUT_REQUEST),
reservedMsgCustomData.data(), msgSize);
msgSize = 0;
2023-07-26 18:20:32 +02:00
ReturnValue_t result = creator.serializeBe(reservedMsgBuf.data(), msgSize, buffer.size());
2023-07-26 17:29:35 +02:00
CHECK(result == returnvalue::OK);
SECTION("Put Request with reserved message") {
2023-07-26 18:20:32 +02:00
PutRequest putRequest(destId, reservedMsgBuf.data(), msgSize, nullptr, 0);
2023-07-26 17:29:35 +02:00
uint8_t* bufPtr = buffer.data();
size_t serLen = 0;
REQUIRE(putRequest.serialize(&bufPtr, &serLen, buffer.size(),
SerializeIF::Endianness::NETWORK) == OK);
2023-07-26 18:20:32 +02:00
2023-07-26 17:29:35 +02:00
CHECK(putRequest.getSerializedSize() == serLen);
2023-07-26 18:20:32 +02:00
PutRequest requestDeserialized;
size_t deserLen = putRequest.getSerializedSize();
const uint8_t* deserPtr = buffer.data();
2023-07-27 14:55:46 +02:00
REQUIRE(requestDeserialized.deSerialize(&deserPtr, &deserLen,
SerializeIF::Endianness::NETWORK) == OK);
2023-07-26 18:20:32 +02:00
CHECK(requestDeserialized.getDestId().getWidth() == destId.getWidth());
CHECK(requestDeserialized.getDestId().getValue() == destId.getValue());
size_t totalMsgsSize = 0;
const uint8_t* msgsToUserStart = requestDeserialized.getMessagesToUser(totalMsgsSize);
CHECK(totalMsgsSize == msgSize);
cfdp::Tlv genericTlv;
genericTlv.deSerialize(&msgsToUserStart, &totalMsgsSize, SerializeIF::Endianness::NETWORK);
CHECK(genericTlv.getType() == TlvType::MSG_TO_USER);
CHECK(genericTlv.getLengthField() == genericTlv.getSerializedSize() - 2);
CHECK(genericTlv.getValue()[0] == 'c');
CHECK(genericTlv.getValue()[1] == 'f');
CHECK(genericTlv.getValue()[2] == 'd');
CHECK(genericTlv.getValue()[3] == 'p');
2023-07-26 17:29:35 +02:00
}
}