contnue msg parser unittest

This commit is contained in:
Robin Müller 2023-07-25 16:16:35 +02:00
parent 244e2d0737
commit 314cba363f
Signed by: muellerr
GPG Key ID: 407F9B00F858F270
6 changed files with 17 additions and 10 deletions

View File

@ -28,7 +28,7 @@ ReturnValue_t cfdp::ReservedMessageParser::parse(const uint8_t* msgsToUserPtr,
return result; return result;
} }
uint8_t messageType = 0; uint8_t messageType = 0;
if (tlv.isReservedCfdpMessage(messageType)) { if (tlv.isReservedCfdpMessage(messageType, &currentPtr, deserSize)) {
if (messageType == static_cast<uint8_t>(ProxyOpMessageType::PUT_REQUEST)) { if (messageType == static_cast<uint8_t>(ProxyOpMessageType::PUT_REQUEST)) {
cfdp::Lv entityIdLv; cfdp::Lv entityIdLv;
result = entityIdLv.deSerialize(&currentPtr, &deserSize, SerializeIF::Endianness::NETWORK); result = entityIdLv.deSerialize(&currentPtr, &deserSize, SerializeIF::Endianness::NETWORK);

View File

@ -49,10 +49,8 @@ ReturnValue_t cfdp::Lv::serialize(uint8_t** buffer, size_t* size, size_t maxSize
} }
size_t cfdp::Lv::getSerializedSize() const { size_t cfdp::Lv::getSerializedSize() const {
if (zeroLen) { if (zeroLen or value.getConstBuffer() == nullptr) {
return 1; return 1;
} else if (value.getConstBuffer() == nullptr) {
return 0;
} }
return value.getSerializedSize(); return value.getSerializedSize();
} }
@ -85,7 +83,7 @@ ReturnValue_t cfdp::Lv::deSerialize(const uint8_t** buffer, size_t* size,
const uint8_t* cfdp::Lv::getValue(size_t* size) const { const uint8_t* cfdp::Lv::getValue(size_t* size) const {
if (size != nullptr) { if (size != nullptr) {
// Length without length field // Length without length field
*size = value.getSerializedSize() - 1; *size = getSerializedSize() - 1;
} }
return value.getConstBuffer(); return value.getConstBuffer();
} }

View File

@ -11,12 +11,17 @@ MessageToUserTlv::MessageToUserTlv(const std::vector<uint8_t>& data)
MessageToUserTlv::MessageToUserTlv(const uint8_t* value, size_t size) MessageToUserTlv::MessageToUserTlv(const uint8_t* value, size_t size)
: Tlv(cfdp::TlvType::MSG_TO_USER, value, size) {} : Tlv(cfdp::TlvType::MSG_TO_USER, value, size) {}
bool MessageToUserTlv::isReservedCfdpMessage(uint8_t& messageType) const { bool MessageToUserTlv::isReservedCfdpMessage(uint8_t& messageType, const uint8_t** msgDataStart,
size_t& msgLen) const {
if (cfdp::Tlv::getLengthField() < 5) { if (cfdp::Tlv::getLengthField() < 5) {
return false; return false;
} }
if (std::strcmp(reinterpret_cast<const char*>(getValue()), "cfdp") == 0) { if (std::strcmp(reinterpret_cast<const char*>(getValue()), "cfdp") == 0) {
messageType = getValue()[4]; messageType = getValue()[4];
if (msgDataStart != nullptr) {
*msgDataStart = getValue() + 5;
}
msgLen = cfdp::Tlv::getSerializedSize() - 5;
return true; return true;
} }
return false; return false;

View File

@ -12,7 +12,8 @@ class MessageToUserTlv : public cfdp::Tlv {
MessageToUserTlv(const uint8_t* value, size_t size); MessageToUserTlv(const uint8_t* value, size_t size);
explicit MessageToUserTlv(const std::vector<uint8_t>& data); explicit MessageToUserTlv(const std::vector<uint8_t>& data);
bool isReservedCfdpMessage(uint8_t& messageType) const; bool isReservedCfdpMessage(uint8_t& messageType, const uint8_t** msgDataStart,
size_t& msgLen) const;
private: private:
}; };

View File

@ -116,8 +116,8 @@ void ObjectManager::initialize() {
<< std::dec << std::setfill(' ') << std::endl; << std::dec << std::setfill(' ') << std::endl;
#else #else
sif::printError( sif::printError(
"ObjectManager::initialize: Object 0x%08x failed to initialize with code 0x%04x\n", var, "ObjectManager::initialize: Object 0x%08x failed to initialize with code 0x%04x\n",
it.first); it.first, result);
#endif #endif
#endif #endif
errorCount++; errorCount++;

View File

@ -5,6 +5,7 @@
#include "fsfw/cfdp/tlv/Lv.h" #include "fsfw/cfdp/tlv/Lv.h"
#include "fsfw/cfdp/tlv/ReservedMessageCreator.h" #include "fsfw/cfdp/tlv/ReservedMessageCreator.h"
#include "fsfw/cfdp/tlv/StringLv.h" #include "fsfw/cfdp/tlv/StringLv.h"
#include "fsfw/globalfunctions/arrayprinter.h"
#include "mocks/MessageQueueMock.h" #include "mocks/MessageQueueMock.h"
#include "mocks/StorageManagerMock.h" #include "mocks/StorageManagerMock.h"
@ -20,6 +21,7 @@ TEST_CASE("Reserved Message Parser", "[cfdp]") {
StorageManagerMock ipcStore(0, storeCfg); StorageManagerMock ipcStore(0, storeCfg);
std::array<uint8_t, 128> buffer{}; std::array<uint8_t, 128> buffer{};
uint8_t msgBuf[32]{}; uint8_t msgBuf[32]{};
EntityId entityId(cfdp::WidthInBytes::ONE_BYTE, 5); EntityId entityId(cfdp::WidthInBytes::ONE_BYTE, 5);
uint8_t* msgBufPtr = msgBuf; uint8_t* msgBufPtr = msgBuf;
size_t serLen = 0; size_t serLen = 0;
@ -35,7 +37,8 @@ TEST_CASE("Reserved Message Parser", "[cfdp]") {
serLen = 0; serLen = 0;
ReturnValue_t result = creator.serializeBe(buffer.data(), serLen, buffer.size()); ReturnValue_t result = creator.serializeBe(buffer.data(), serLen, buffer.size());
CHECK(result == returnvalue::OK); CHECK(result == returnvalue::OK);
arrayprinter::print(buffer.data(), serLen);
ReservedMessageParser parser(ipcStore, msgQueue, destQueueId); ReservedMessageParser parser(ipcStore, msgQueue, destQueueId);
CHECK(parser.parse(buffer.data(), buffer.max_size()) == OK); CHECK(parser.parse(buffer.data(), serLen) == OK);
} }