fsfw/unittests/cfdp/handler/testReservedMsgParser.cpp

45 lines
1.7 KiB
C++
Raw Normal View History

#include <catch2/catch_test_macros.hpp>
2023-07-25 13:58:22 +02:00
#include "fsfw/cfdp/VarLenFields.h"
#include "fsfw/cfdp/handler/ReservedMessageParser.h"
2023-07-25 13:58:22 +02:00
#include "fsfw/cfdp/tlv/Lv.h"
#include "fsfw/cfdp/tlv/ReservedMessageCreator.h"
#include "fsfw/cfdp/tlv/StringLv.h"
2023-07-25 16:16:35 +02:00
#include "fsfw/globalfunctions/arrayprinter.h"
#include "mocks/MessageQueueMock.h"
#include "mocks/StorageManagerMock.h"
TEST_CASE("Reserved Message Parser", "[cfdp]") {
using namespace cfdp;
using namespace returnvalue;
2023-07-25 13:58:22 +02:00
std::string srcFileName = "hello.txt";
std::string destFileName = "hello2.txt";
MessageQueueId_t destQueueId = 2;
MessageQueueMock msgQueue(destQueueId);
LocalPool::LocalPoolConfig storeCfg = {{10, 32}, {10, 64}, {10, 128}, {10, 1024}};
StorageManagerMock ipcStore(0, storeCfg);
2023-07-25 13:58:22 +02:00
std::array<uint8_t, 128> buffer{};
uint8_t msgBuf[32]{};
2023-07-25 16:16:35 +02:00
2023-07-25 13:58:22 +02:00
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);
2023-07-25 16:16:35 +02:00
arrayprinter::print(buffer.data(), serLen);
2023-07-25 13:58:22 +02:00
ReservedMessageParser parser(ipcStore, msgQueue, destQueueId);
2023-07-25 16:16:35 +02:00
CHECK(parser.parse(buffer.data(), serLen) == OK);
}