fsfw/unittests/tmtcservices/testStoreAndSendHelper.cpp

88 lines
3.4 KiB
C++
Raw Normal View History

2022-07-26 11:19:36 +02:00
#include <catch2/catch_test_macros.hpp>
#include "fsfw/storagemanager/LocalPool.h"
#include "fsfw/tmtcservices/TmSendHelper.h"
2022-07-26 13:59:09 +02:00
#include "fsfw/tmtcservices/TmStoreAndSendHelper.h"
2022-07-26 11:19:36 +02:00
#include "fsfw/tmtcservices/TmStoreHelper.h"
#include "mocks/CdsShortTimestamperMock.h"
2022-07-26 13:59:09 +02:00
#include "mocks/InternalErrorReporterMock.h"
#include "mocks/MessageQueueMock.h"
#include "mocks/SimpleSerializable.h"
2022-07-26 11:19:36 +02:00
TEST_CASE("TM Store And Send Helper", "[tm-store-send-helper]") {
auto timeStamper = CdsShortTimestamperMock();
LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}};
LocalPool pool(objects::NO_OBJECT, cfg);
auto storeHelper = TmStoreHelper(2, pool, timeStamper);
MessageQueueId_t destId = 1;
auto errReporter = InternalErrorReporterMock();
auto msgQueue = MessageQueueMock(2);
2022-07-26 11:19:36 +02:00
msgQueue.setDefaultDestination(destId);
TmSendHelper sendHelper(msgQueue, errReporter, destId);
2022-07-26 13:59:09 +02:00
TmStoreAndSendWrapper tmHelper(17, storeHelper, sendHelper);
SECTION("State") {
CHECK(tmHelper.sendCounter == 0);
CHECK(tmHelper.defaultService == 17);
CHECK(tmHelper.delOnFailure);
CHECK(tmHelper.incrementSendCounter);
CHECK(&tmHelper.sendHelper == &sendHelper);
CHECK(&tmHelper.storeHelper == &storeHelper);
}
SECTION("Base Test") {
tmHelper.prepareTmPacket(2);
auto& creator = storeHelper.getCreatorRef();
REQUIRE(creator.getSubService() == 2);
REQUIRE(creator.getService() == 17);
auto& params = creator.getParams();
REQUIRE(params.dataWrapper.type == ecss::DataTypes::RAW);
REQUIRE(params.dataWrapper.dataUnion.raw.data == nullptr);
REQUIRE(params.dataWrapper.dataUnion.raw.len == 0);
REQUIRE(tmHelper.sendCounter == 0);
2022-07-28 13:00:53 +02:00
REQUIRE(tmHelper.storeAndSendTmPacket() == result::OK);
2022-07-26 13:59:09 +02:00
REQUIRE(tmHelper.sendCounter == 1);
auto storeId = storeHelper.getCurrentAddr();
REQUIRE(msgQueue.wasMessageSent());
REQUIRE(msgQueue.numberOfSentMessagesToDefault() == 1);
TmTcMessage msg;
2022-07-28 13:00:53 +02:00
REQUIRE(msgQueue.getNextSentMessage(msg) == result::OK);
2022-07-26 13:59:09 +02:00
REQUIRE(msg.getStorageId() == storeId);
REQUIRE(pool.hasDataAtId(msg.getStorageId()));
storeHelper.deletePacket();
}
SECTION("Raw Data Helper") {
std::array<uint8_t, 3> data = {1, 2, 3};
2022-07-28 13:00:53 +02:00
REQUIRE(tmHelper.prepareTmPacket(2, data.data(), data.size()) == result::OK);
2022-07-26 13:59:09 +02:00
auto& creator = storeHelper.getCreatorRef();
auto& params = creator.getParams();
REQUIRE(params.dataWrapper.type == ecss::DataTypes::RAW);
REQUIRE(params.dataWrapper.dataUnion.raw.data == data.data());
REQUIRE(params.dataWrapper.dataUnion.raw.len == data.size());
}
SECTION("Serializable Helper") {
auto simpleSer = SimpleSerializable();
2022-07-28 13:00:53 +02:00
REQUIRE(tmHelper.prepareTmPacket(2, simpleSer) == result::OK);
2022-07-26 13:59:09 +02:00
auto& creator = storeHelper.getCreatorRef();
auto& params = creator.getParams();
REQUIRE(params.dataWrapper.type == ecss::DataTypes::SERIALIZABLE);
REQUIRE(params.dataWrapper.dataUnion.serializable == &simpleSer);
}
SECTION("Object ID prefix Helper") {
uint32_t objectId = 0x01020304;
std::array<uint8_t, 3> data = {1, 2, 3};
telemetry::DataWithObjectIdPrefix dataWithObjId(objectId, data.data(), data.size());
2022-07-28 13:00:53 +02:00
REQUIRE(tmHelper.prepareTmPacket(2, dataWithObjId) == result::OK);
2022-07-26 13:59:09 +02:00
auto& creator = storeHelper.getCreatorRef();
auto& params = creator.getParams();
REQUIRE(params.dataWrapper.type == ecss::DataTypes::SERIALIZABLE);
REQUIRE(params.dataWrapper.dataUnion.serializable == &dataWithObjId);
}
// TODO: Error handling
2022-07-26 11:19:36 +02:00
}