#include #include #include "fsfw/cfdp/CfdpMessage.h" #include "fsfw/cfdp/VarLenFields.h" #include "fsfw/cfdp/handler/PutRequest.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 "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/serialize.h" #include "mocks/MessageQueueMock.h" #include "mocks/StorageManagerMock.h" TEST_CASE("Reserved Message Parser", "[cfdp]") { using namespace cfdp; using namespace returnvalue; std::string srcFileName = "hello.txt"; std::string destFileName = "hello2.txt"; MessageQueueId_t destQueueId = 2; MessageQueueMock msgQueue(1); LocalPool::LocalPoolConfig storeCfg = {{10, 32}, {10, 64}, {10, 128}, {10, 1024}}; StorageManagerMock ipcStore(0, storeCfg); std::array 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(ProxyOpMessageType::PUT_REQUEST), msgBuf, serLen); serLen = 0; ReturnValue_t result = creator.serializeBe(buffer.data(), serLen, buffer.size()); CHECK(result == returnvalue::OK); MessageToUserTlv msgToUser; CHECK(msgToUser.deSerializeBe(buffer.data(), serLen, buffer.size()) == OK); ReservedMessageParser parser(ipcStore, msgQueue, destQueueId); REQUIRE(parser.parse(&msgToUser, 1) == OK); 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; CHECK(ipcStore.getData(storeId, &data, &packetLen) == OK); CHECK(packetLen > 0); PutRequest putRequest; size_t dummy = packetLen; REQUIRE(putRequest.deSerialize(&data, &dummy, SerializeIF::Endianness::MACHINE) == OK); CHECK(putRequest.getDestId().getValue() == entityId.getValue()); CHECK(putRequest.getDestId().getWidth() == entityId.getWidth()); auto& sourceNameLv = putRequest.getSourceName(); std::string srcNameRead = sourceNameLv.getString(); CHECK(srcNameRead == srcFileName); auto& destNameLv = putRequest.getDestName(); std::string destNameRead = destNameLv.getString(); CHECK(destNameRead == destFileName); }