start adding message parser unittests
This commit is contained in:
parent
8f0974d83e
commit
244e2d0737
@ -74,6 +74,19 @@ struct EntityId : public VarLenField {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
explicit EntityId(UnsignedByteField<T> byteField) : VarLenField(byteField) {}
|
explicit EntityId(UnsignedByteField<T> byteField) : VarLenField(byteField) {}
|
||||||
EntityId(cfdp::WidthInBytes width, size_t entityId) : VarLenField(width, entityId) {}
|
EntityId(cfdp::WidthInBytes width, size_t entityId) : VarLenField(width, entityId) {}
|
||||||
|
|
||||||
|
ReturnValue_t serializeAsLv(uint8_t **buffer, size_t *size, size_t maxSize) {
|
||||||
|
if (buffer == nullptr or size == nullptr) {
|
||||||
|
return returnvalue::FAILED;
|
||||||
|
}
|
||||||
|
if (*size + 1 + getWidth() > maxSize) {
|
||||||
|
return SerializeIF::BUFFER_TOO_SHORT;
|
||||||
|
}
|
||||||
|
**buffer = getWidth();
|
||||||
|
*buffer += 1;
|
||||||
|
*size += 1;
|
||||||
|
return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TransactionSeqNum : public VarLenField {
|
struct TransactionSeqNum : public VarLenField {
|
||||||
|
@ -13,7 +13,7 @@ ReturnValue_t cfdp::ReservedMessageCreator::serialize(
|
|||||||
**buffer = TlvType::MSG_TO_USER;
|
**buffer = TlvType::MSG_TO_USER;
|
||||||
*buffer += 1;
|
*buffer += 1;
|
||||||
*size += 1;
|
*size += 1;
|
||||||
**buffer = getSerializedSize() - 1;
|
**buffer = getSerializedSize() - 2;
|
||||||
*size += 1;
|
*size += 1;
|
||||||
*buffer += 1;
|
*buffer += 1;
|
||||||
std::memcpy(*buffer, MSG_HEADER, 4);
|
std::memcpy(*buffer, MSG_HEADER, 4);
|
||||||
@ -23,6 +23,8 @@ ReturnValue_t cfdp::ReservedMessageCreator::serialize(
|
|||||||
*buffer += 1;
|
*buffer += 1;
|
||||||
*size += 1;
|
*size += 1;
|
||||||
std::memcpy(*buffer, msgData, msgSize);
|
std::memcpy(*buffer, msgData, msgSize);
|
||||||
|
*buffer += msgSize;
|
||||||
|
*size += msgSize;
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
target_sources(${FSFW_TEST_TGT} PRIVATE testCfdp.cpp testOtherTlvs.cpp
|
target_sources(
|
||||||
testTlv.cpp testLvs.cpp)
|
${FSFW_TEST_TGT} PRIVATE testCfdp.cpp testOtherTlvs.cpp
|
||||||
|
testReservedMsgCreator.cpp testTlv.cpp testLvs.cpp)
|
||||||
|
|
||||||
add_subdirectory(handler)
|
add_subdirectory(handler)
|
||||||
add_subdirectory(pdu)
|
add_subdirectory(pdu)
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
|
||||||
|
#include "fsfw/cfdp/VarLenFields.h"
|
||||||
#include "fsfw/cfdp/handler/ReservedMessageParser.h"
|
#include "fsfw/cfdp/handler/ReservedMessageParser.h"
|
||||||
|
#include "fsfw/cfdp/tlv/Lv.h"
|
||||||
|
#include "fsfw/cfdp/tlv/ReservedMessageCreator.h"
|
||||||
|
#include "fsfw/cfdp/tlv/StringLv.h"
|
||||||
#include "mocks/MessageQueueMock.h"
|
#include "mocks/MessageQueueMock.h"
|
||||||
#include "mocks/StorageManagerMock.h"
|
#include "mocks/StorageManagerMock.h"
|
||||||
|
|
||||||
@ -8,11 +12,30 @@ TEST_CASE("Reserved Message Parser", "[cfdp]") {
|
|||||||
using namespace cfdp;
|
using namespace cfdp;
|
||||||
using namespace returnvalue;
|
using namespace returnvalue;
|
||||||
|
|
||||||
|
std::string srcFileName = "hello.txt";
|
||||||
|
std::string destFileName = "hello2.txt";
|
||||||
MessageQueueId_t destQueueId = 2;
|
MessageQueueId_t destQueueId = 2;
|
||||||
MessageQueueMock msgQueue(destQueueId);
|
MessageQueueMock msgQueue(destQueueId);
|
||||||
LocalPool::LocalPoolConfig storeCfg = {{10, 32}, {10, 64}, {10, 128}, {10, 1024}};
|
LocalPool::LocalPoolConfig storeCfg = {{10, 32}, {10, 64}, {10, 128}, {10, 1024}};
|
||||||
StorageManagerMock ipcStore(0, storeCfg);
|
StorageManagerMock ipcStore(0, storeCfg);
|
||||||
ReservedMessageParser parser(ipcStore, msgQueue, destQueueId);
|
std::array<uint8_t, 128> 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);
|
||||||
|
|
||||||
// parser.parse()
|
ReservedMessageParser parser(ipcStore, msgQueue, destQueueId);
|
||||||
|
CHECK(parser.parse(buffer.data(), buffer.max_size()) == OK);
|
||||||
}
|
}
|
||||||
|
49
unittests/cfdp/testReservedMsgCreator.cpp
Normal file
49
unittests/cfdp/testReservedMsgCreator.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user