2023-07-24 18:01:25 +02:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
|
2023-07-26 16:58:58 +02:00
|
|
|
#include "fsfw/cfdp/CfdpMessage.h"
|
2023-07-25 13:58:22 +02:00
|
|
|
#include "fsfw/cfdp/VarLenFields.h"
|
2023-07-26 16:58:58 +02:00
|
|
|
#include "fsfw/cfdp/handler/PutRequest.h"
|
2023-07-24 18:01:25 +02:00
|
|
|
#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"
|
2023-07-26 16:58:58 +02:00
|
|
|
#include "fsfw/serialize.h"
|
2023-07-24 18:01:25 +02:00
|
|
|
#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";
|
2023-07-24 18:01:25 +02:00
|
|
|
MessageQueueId_t destQueueId = 2;
|
2023-07-26 16:36:21 +02:00
|
|
|
MessageQueueMock msgQueue(1);
|
2023-07-24 18:01:25 +02:00
|
|
|
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-24 18:01:25 +02:00
|
|
|
|
2023-07-25 13:58:22 +02:00
|
|
|
ReservedMessageParser parser(ipcStore, msgQueue, destQueueId);
|
2023-07-26 16:58:58 +02:00
|
|
|
REQUIRE(parser.parse(buffer.data(), serLen) == OK);
|
2023-07-26 16:36:21 +02:00
|
|
|
CommandMessage msg;
|
|
|
|
CHECK(msgQueue.wasMessageSent());
|
|
|
|
CHECK(msgQueue.numberOfSentMessages() == 1);
|
|
|
|
CHECK(msgQueue.getNextSentMessage(destQueueId, msg) == OK);
|
|
|
|
store_address_t storeId = CfdpMessage::getStoreId(&msg);
|
|
|
|
const uint8_t* data;
|
|
|
|
size_t packetLen;
|
2023-07-26 16:58:58 +02:00
|
|
|
CHECK(ipcStore.getData(storeId, &data, &packetLen) == OK);
|
2023-07-26 16:36:21 +02:00
|
|
|
CHECK(packetLen > 0);
|
2023-07-26 16:58:58 +02:00
|
|
|
PutRequest putRequest;
|
|
|
|
size_t dummy = packetLen;
|
2023-07-26 17:17:51 +02:00
|
|
|
REQUIRE(putRequest.deSerialize(&data, &dummy, SerializeIF::Endianness::MACHINE) == OK);
|
|
|
|
CHECK(putRequest.getDestId().getValue() == entityId.getValue());
|
|
|
|
CHECK(putRequest.getDestId().getWidth() == entityId.getWidth());
|
2023-07-27 14:55:46 +02:00
|
|
|
size_t sourceNameSize = 0;
|
|
|
|
auto& sourceNameLv = putRequest.getSourceName();
|
2023-07-27 15:07:14 +02:00
|
|
|
const char* sourceString = sourceNameLv.getString(sourceNameSize);
|
2023-07-27 14:55:46 +02:00
|
|
|
CHECK(sourceNameSize == srcFileName.size());
|
2023-07-27 15:07:14 +02:00
|
|
|
CHECK(std::strncmp(sourceString, srcFileName.c_str(), sourceNameSize) == 0);
|
|
|
|
size_t destNameSize = 0;
|
|
|
|
auto& destNameLv = putRequest.getDestName();
|
|
|
|
const char* destString = destNameLv.getString(destNameSize);
|
|
|
|
CHECK(destNameSize == destFileName.size());
|
|
|
|
CHECK(std::strncmp(destString, destFileName.c_str(), destNameSize) == 0);
|
2023-07-24 18:01:25 +02:00
|
|
|
}
|