reserved message unittest working

This commit is contained in:
Robin Müller 2023-07-26 18:20:32 +02:00
parent 947f2b8685
commit 5679b139ad
Signed by: muellerr
GPG Key ID: 407F9B00F858F270
4 changed files with 33 additions and 3 deletions

View File

@ -117,6 +117,7 @@ ReturnValue_t cfdp::VarLenField::deSerialize(const uint8_t **buffer, size_t *siz
switch (width) {
case (cfdp::WidthInBytes::ONE_BYTE): {
value.oneByte = **buffer;
*buffer += 1;
*size += 1;
return returnvalue::OK;
}

View File

@ -106,6 +106,10 @@ ReturnValue_t cfdp::PutRequest::deSerialize(const uint8_t **buffer, size_t *size
if (result != OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hasTransmissionMode, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
result = SerializeAdapter::deSerialize(&transmissionMode, buffer, size, streamEndianness);
if (result != OK) {
return result;
@ -141,7 +145,7 @@ size_t cfdp::PutRequest::getSerializedSize() const {
// Entity ID LV (1 leading size byte) and the metadata only flag.
size_t baseSize = 1 + destId.getSerializedSize() + 1;
if (!metadataOnly) {
baseSize += sourceName.getSerializedSize() + destName.getSerializedSize() + 2;
baseSize += sourceName.getSerializedSize() + destName.getSerializedSize() + 4;
}
baseSize += sizeof(msgsToUsersTotalSize) + msgsToUsersTotalSize + sizeof(fsRequestsTotalSize) +
fsRequestsTotalSize;
@ -175,3 +179,8 @@ void cfdp::PutRequest::setClosureRequest(bool closureRequested_) {
this->closureRequested = closureRequested_;
hasClosureRequested = true;
}
const uint8_t *cfdp::PutRequest::getMessagesToUser(size_t &totalSize) {
totalSize = this->msgsToUsersTotalSize;
return msgsToUserStartPtr;
}

View File

@ -49,6 +49,8 @@ class PutRequest : public SerializeIF {
void setClosureRequest(bool closureRequested);
void clearClosureRequest();
const uint8_t* getMessagesToUser(size_t& msgSize);
[[nodiscard]] bool isMetadataOnly() const;
[[nodiscard]] const EntityId& getDestId() const;

View File

@ -26,15 +26,33 @@ TEST_CASE("Put Request", "[cfdp]") {
ReservedMessageCreator creator(static_cast<uint8_t>(ProxyOpMessageType::PUT_REQUEST),
reservedMsgCustomData.data(), msgSize);
msgSize = 0;
ReturnValue_t result = creator.serializeBe(buffer.data(), msgSize, buffer.size());
ReturnValue_t result = creator.serializeBe(reservedMsgBuf.data(), msgSize, buffer.size());
CHECK(result == returnvalue::OK);
SECTION("Put Request with reserved message") {
PutRequest putRequest(destId, reservedMsgCustomData.data(), msgSize, nullptr, 0);
PutRequest putRequest(destId, reservedMsgBuf.data(), msgSize, nullptr, 0);
uint8_t* bufPtr = buffer.data();
size_t serLen = 0;
REQUIRE(putRequest.serialize(&bufPtr, &serLen, buffer.size(),
SerializeIF::Endianness::NETWORK) == OK);
CHECK(putRequest.getSerializedSize() == serLen);
PutRequest requestDeserialized;
size_t deserLen = putRequest.getSerializedSize();
const uint8_t* deserPtr = buffer.data();
REQUIRE(requestDeserialized.deSerialize(&deserPtr, &deserLen, SerializeIF::Endianness::NETWORK) == OK);
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');
}
}