test auto-initializers

This commit is contained in:
Robin Müller 2022-07-26 18:46:28 +02:00
parent 1954ce0ea4
commit 8bf0fb9885
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
18 changed files with 215 additions and 52 deletions

View File

@ -36,7 +36,7 @@ void Factory::produceFsfwObjects(void) {
void Factory::setStaticFrameworkObjectIds() { void Factory::setStaticFrameworkObjectIds() {
PusServiceBase::packetSource = objects::NO_OBJECT; PusServiceBase::packetSource = objects::NO_OBJECT;
PusServiceBase::packetDestination = objects::NO_OBJECT; PusServiceBase::PACKET_DESTINATION = objects::NO_OBJECT;
CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT; CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT;
CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT; CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT;

View File

@ -104,9 +104,12 @@ ReturnValue_t CommandingServiceBase::initialize() {
errReporter = errReporter =
ObjectManager::instance()->get<InternalErrorReporterIF>(objects::INTERNAL_ERROR_REPORTER); ObjectManager::instance()->get<InternalErrorReporterIF>(objects::INTERNAL_ERROR_REPORTER);
if (errReporter != nullptr) { if (errReporter != nullptr) {
tmSendHelper.setInternalErrorReporter(errReporter); tmSendHelper.setInternalErrorReporter(*errReporter);
} }
} else {
tmSendHelper.setInternalErrorReporter(*errReporter);
} }
if (verificationReporter == nullptr) { if (verificationReporter == nullptr) {
verificationReporter = verificationReporter =
ObjectManager::instance()->get<VerificationReporterIF>(objects::TC_VERIFICATOR); ObjectManager::instance()->get<VerificationReporterIF>(objects::TC_VERIFICATOR);

View File

@ -18,7 +18,7 @@
namespace Factory { namespace Factory {
void setStaticFrameworkObjectIds(); void setStaticFrameworkObjectIds();
} };
/** /**
* @brief This class is the basis for all PUS Services, which have to * @brief This class is the basis for all PUS Services, which have to
@ -38,7 +38,7 @@ class CommandingServiceBase : public SystemObject,
public AcceptsTelecommandsIF, public AcceptsTelecommandsIF,
public ExecutableObjectIF, public ExecutableObjectIF,
public HasReturnvaluesIF { public HasReturnvaluesIF {
friend void(Factory::setStaticFrameworkObjectIds)(); friend void Factory::setStaticFrameworkObjectIds();
public: public:
// We could make this configurable via preprocessor and the FSFWConfig file. // We could make this configurable via preprocessor and the FSFWConfig file.

View File

@ -9,8 +9,8 @@
#include "fsfw/tmtcservices/TmTcMessage.h" #include "fsfw/tmtcservices/TmTcMessage.h"
#include "fsfw/tmtcservices/tcHelpers.h" #include "fsfw/tmtcservices/tcHelpers.h"
object_id_t PusServiceBase::packetDestination = 0; object_id_t PusServiceBase::PACKET_DESTINATION = 0;
object_id_t PusServiceBase::pusDistributor = 0; object_id_t PusServiceBase::PUS_DISTRIBUTOR = 0;
PusServiceBase::PusServiceBase(PsbParams params) PusServiceBase::PusServiceBase(PsbParams params)
: SystemObject(params.objectId), psbParams(params) {} : SystemObject(params.objectId), psbParams(params) {}
@ -83,7 +83,12 @@ void PusServiceBase::handleRequestQueue() {
uint16_t PusServiceBase::getIdentifier() { return psbParams.serviceId; } uint16_t PusServiceBase::getIdentifier() { return psbParams.serviceId; }
MessageQueueId_t PusServiceBase::getRequestQueue() { return psbParams.reqQueue->getId(); } MessageQueueId_t PusServiceBase::getRequestQueue() {
if (psbParams.reqQueue == nullptr) {
return MessageQueueIF::NO_QUEUE;
}
return psbParams.reqQueue->getId();
}
ReturnValue_t PusServiceBase::initialize() { ReturnValue_t PusServiceBase::initialize() {
ReturnValue_t result = SystemObject::initialize(); ReturnValue_t result = SystemObject::initialize();
@ -96,15 +101,16 @@ ReturnValue_t PusServiceBase::initialize() {
} else { } else {
ownedQueue = false; ownedQueue = false;
} }
if (psbParams.tmReceiver == nullptr) { if (psbParams.tmReceiver == nullptr) {
psbParams.tmReceiver = ObjectManager::instance()->get<AcceptsTelemetryIF>(packetDestination); psbParams.tmReceiver = ObjectManager::instance()->get<AcceptsTelemetryIF>(PACKET_DESTINATION);
if (psbParams.tmReceiver != nullptr) { if (psbParams.tmReceiver != nullptr) {
psbParams.reqQueue->setDefaultDestination(psbParams.tmReceiver->getReportReceptionQueue()); psbParams.reqQueue->setDefaultDestination(psbParams.tmReceiver->getReportReceptionQueue());
} }
} }
if (psbParams.pusDistributor != nullptr) { if (psbParams.pusDistributor == nullptr) {
psbParams.pusDistributor = ObjectManager::instance()->get<PUSDistributorIF>(pusDistributor); psbParams.pusDistributor = ObjectManager::instance()->get<PUSDistributorIF>(PUS_DISTRIBUTOR);
if (psbParams.pusDistributor != nullptr) { if (psbParams.pusDistributor != nullptr) {
registerService(*psbParams.pusDistributor); registerService(*psbParams.pusDistributor);
} }
@ -127,17 +133,10 @@ ReturnValue_t PusServiceBase::initialize() {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t PusServiceBase::initializeAfterTaskCreation() { void PusServiceBase::setTcPool(StorageManagerIF& tcPool) { psbParams.tcPool = &tcPool; }
// If task parameters, for example task frequency are required, this
// function should be overriden and the system object task IF can
// be used to get those parameters.
return HasReturnvaluesIF::RETURN_OK;
}
void PusServiceBase::setCustomTcStore(StorageManagerIF* tcPool) { psbParams.tcPool = tcPool; } void PusServiceBase::setErrorReporter(InternalErrorReporterIF& errReporter_) {
psbParams.errReporter = &errReporter_;
void PusServiceBase::setCustomErrorReporter(InternalErrorReporterIF* errReporter_) {
psbParams.errReporter = errReporter_;
} }
void PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelper& tmStoreHelper) { void PusServiceBase::initializeTmHelpers(TmSendHelper& tmSendHelper, TmStoreHelper& tmStoreHelper) {
@ -155,8 +154,10 @@ void PusServiceBase::initializeTmSendHelper(TmSendHelper& tmSendHelper) {
psbParams.errReporter = psbParams.errReporter =
ObjectManager::instance()->get<InternalErrorReporterIF>(objects::INTERNAL_ERROR_REPORTER); ObjectManager::instance()->get<InternalErrorReporterIF>(objects::INTERNAL_ERROR_REPORTER);
if (psbParams.errReporter != nullptr) { if (psbParams.errReporter != nullptr) {
tmSendHelper.setInternalErrorReporter(psbParams.errReporter); tmSendHelper.setInternalErrorReporter(*psbParams.errReporter);
} }
} else {
tmSendHelper.setInternalErrorReporter(*psbParams.errReporter);
} }
} }
@ -164,16 +165,16 @@ void PusServiceBase::initializeTmStoreHelper(TmStoreHelper& tmStoreHelper) const
tmStoreHelper.setApid(psbParams.apid); tmStoreHelper.setApid(psbParams.apid);
} }
void PusServiceBase::setVerificationReporter(VerificationReporterIF* reporter) { void PusServiceBase::setVerificationReporter(VerificationReporterIF& reporter) {
psbParams.verifReporter = reporter; psbParams.verifReporter = &reporter;
} }
ReturnValue_t PusServiceBase::registerService(PUSDistributorIF& distributor) { ReturnValue_t PusServiceBase::registerService(PUSDistributorIF& distributor) {
return distributor.registerService(this); return distributor.registerService(this);
} }
void PusServiceBase::setTmReceiver(AcceptsTelemetryIF* tmReceiver_) { void PusServiceBase::setTmReceiver(AcceptsTelemetryIF& tmReceiver_) {
psbParams.tmReceiver = tmReceiver_; psbParams.tmReceiver = &tmReceiver_;
} }
void PusServiceBase::setRequestQueue(MessageQueueIF* reqQueue) { psbParams.reqQueue = reqQueue; } void PusServiceBase::setRequestQueue(MessageQueueIF& reqQueue) { psbParams.reqQueue = &reqQueue; }

View File

@ -14,10 +14,6 @@
#include "fsfw/tasks/ExecutableObjectIF.h" #include "fsfw/tasks/ExecutableObjectIF.h"
#include "fsfw/tcdistribution/PUSDistributorIF.h" #include "fsfw/tcdistribution/PUSDistributorIF.h"
namespace Factory {
void setStaticFrameworkObjectIds();
}
class StorageManagerIF; class StorageManagerIF;
/** /**
@ -71,6 +67,10 @@ struct PsbParams {
PUSDistributorIF* pusDistributor = nullptr; PUSDistributorIF* pusDistributor = nullptr;
}; };
namespace Factory {
void setStaticFrameworkObjectIds();
}
/** /**
* @defgroup pus_services PUS Service Framework * @defgroup pus_services PUS Service Framework
* These group contains all implementations of PUS Services in the OBSW. * These group contains all implementations of PUS Services in the OBSW.
@ -93,7 +93,7 @@ class PusServiceBase : public ExecutableObjectIF,
public AcceptsTelecommandsIF, public AcceptsTelecommandsIF,
public SystemObject, public SystemObject,
public HasReturnvaluesIF { public HasReturnvaluesIF {
friend void(Factory::setStaticFrameworkObjectIds)(); friend void Factory::setStaticFrameworkObjectIds();
public: public:
/** /**
@ -121,11 +121,11 @@ class PusServiceBase : public ExecutableObjectIF,
* function will create one * function will create one
* @param reqQueue * @param reqQueue
*/ */
void setRequestQueue(MessageQueueIF* reqQueue); void setRequestQueue(MessageQueueIF& reqQueue);
void setTmReceiver(AcceptsTelemetryIF* tmReceiver); void setTmReceiver(AcceptsTelemetryIF& tmReceiver);
void setCustomTcStore(StorageManagerIF* tcStore); void setTcPool(StorageManagerIF& tcStore);
void setVerificationReporter(VerificationReporterIF* reporter); void setVerificationReporter(VerificationReporterIF& reporter);
void setCustomErrorReporter(InternalErrorReporterIF* errReporter); void setErrorReporter(InternalErrorReporterIF& errReporter);
/** /**
* Helper methods if the implementing class wants to send telemetry * Helper methods if the implementing class wants to send telemetry
@ -190,7 +190,6 @@ class PusServiceBase : public ExecutableObjectIF,
ReturnValue_t initialize() override; ReturnValue_t initialize() override;
void setTaskIF(PeriodicTaskIF* taskHandle) override; void setTaskIF(PeriodicTaskIF* taskHandle) override;
ReturnValue_t initializeAfterTaskCreation() override;
protected: protected:
/** /**
@ -215,9 +214,8 @@ class PusServiceBase : public ExecutableObjectIF,
PusTcReader currentPacket; PusTcReader currentPacket;
bool ownedQueue = true; bool ownedQueue = true;
static object_id_t packetDestination; static object_id_t PACKET_DESTINATION;
static object_id_t pusDistributor; static object_id_t PUS_DISTRIBUTOR;
VerifSuccessParams successParams;
private: private:
void handleRequestQueue(); void handleRequestQueue();

View File

@ -30,8 +30,8 @@ ReturnValue_t TmSendHelper::sendPacket(const store_address_t &storeId) {
void TmSendHelper::setDefaultDestination(MessageQueueId_t msgDest) { defaultDest = msgDest; } void TmSendHelper::setDefaultDestination(MessageQueueId_t msgDest) { defaultDest = msgDest; }
void TmSendHelper::setInternalErrorReporter(InternalErrorReporterIF *reporter) { void TmSendHelper::setInternalErrorReporter(InternalErrorReporterIF &reporter) {
errReporter = reporter; errReporter = &reporter;
} }
void TmSendHelper::setMsgQueue(MessageQueueIF &queue_) { queue = &queue_; } void TmSendHelper::setMsgQueue(MessageQueueIF &queue_) { queue = &queue_; }

View File

@ -23,7 +23,7 @@ class TmSendHelper {
[[nodiscard]] bool areFaultsIgnored() const; [[nodiscard]] bool areFaultsIgnored() const;
void ignoreFaults(); void ignoreFaults();
void dontIgnoreFaults(); void dontIgnoreFaults();
void setInternalErrorReporter(InternalErrorReporterIF* reporter); void setInternalErrorReporter(InternalErrorReporterIF& reporter);
[[nodiscard]] InternalErrorReporterIF* getInternalErrorReporter() const; [[nodiscard]] InternalErrorReporterIF* getInternalErrorReporter() const;
ReturnValue_t sendPacket(MessageQueueId_t dest, const store_address_t& storeId); ReturnValue_t sendPacket(MessageQueueId_t dest, const store_address_t& storeId);
ReturnValue_t sendPacket(const store_address_t& storeId); ReturnValue_t sendPacket(const store_address_t& storeId);

View File

@ -54,7 +54,7 @@ void Factory::produceFrameworkObjects(void* args) {
// like this. Instead, this should be more like a general struct containing all important // like this. Instead, this should be more like a general struct containing all important
// object IDs which are then explicitely passed in the object constructor // object IDs which are then explicitely passed in the object constructor
void Factory::setStaticFrameworkObjectIds() { void Factory::setStaticFrameworkObjectIds() {
PusServiceBase::packetDestination = objects::NO_OBJECT; PusServiceBase::PACKET_DESTINATION = objects::NO_OBJECT;
CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT; CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT;
CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT; CommandingServiceBase::defaultPacketDestination = objects::NO_OBJECT;
@ -62,9 +62,7 @@ void Factory::setStaticFrameworkObjectIds() {
DeviceHandlerBase::powerSwitcherId = objects::NO_OBJECT; DeviceHandlerBase::powerSwitcherId = objects::NO_OBJECT;
DeviceHandlerBase::rawDataReceiverId = objects::NO_OBJECT; DeviceHandlerBase::rawDataReceiverId = objects::NO_OBJECT;
// TODO: Incredibly ugly, get rid of it
LocalDataPoolManager::defaultHkDestination = objects::NO_OBJECT; LocalDataPoolManager::defaultHkDestination = objects::NO_OBJECT;
DeviceHandlerFailureIsolation::powerConfirmationId = objects::NO_OBJECT; DeviceHandlerFailureIsolation::powerConfirmationId = objects::NO_OBJECT;
} }

View File

@ -1,6 +1,10 @@
#include "AcceptsTmMock.h" #include "AcceptsTmMock.h"
AcceptsTmMock::AcceptsTmMock(MessageQueueId_t queueToReturn) : returnedQueue(queueToReturn) {} AcceptsTmMock::AcceptsTmMock(object_id_t registeredId, MessageQueueId_t queueToReturn)
: SystemObject(registeredId), returnedQueue(queueToReturn) {}
AcceptsTmMock::AcceptsTmMock(MessageQueueId_t queueToReturn)
: SystemObject(objects::NO_OBJECT, false), returnedQueue(queueToReturn) {}
MessageQueueId_t AcceptsTmMock::getReportReceptionQueue(uint8_t virtualChannel) { MessageQueueId_t AcceptsTmMock::getReportReceptionQueue(uint8_t virtualChannel) {
return returnedQueue; return returnedQueue;

View File

@ -1,10 +1,12 @@
#ifndef FSFW_TESTS_ACCEPTSTMMOCK_H #ifndef FSFW_TESTS_ACCEPTSTMMOCK_H
#define FSFW_TESTS_ACCEPTSTMMOCK_H #define FSFW_TESTS_ACCEPTSTMMOCK_H
#include "fsfw/objectmanager/SystemObject.h"
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h" #include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
class AcceptsTmMock : public AcceptsTelemetryIF { class AcceptsTmMock : public SystemObject, public AcceptsTelemetryIF {
public: public:
AcceptsTmMock(object_id_t registeredId, MessageQueueId_t queueToReturn);
explicit AcceptsTmMock(MessageQueueId_t queueToReturn); explicit AcceptsTmMock(MessageQueueId_t queueToReturn);
MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) override; MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) override;

View File

@ -10,4 +10,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE
PusVerificationReporterMock.cpp PusVerificationReporterMock.cpp
PusServiceBaseMock.cpp PusServiceBaseMock.cpp
AcceptsTmMock.cpp AcceptsTmMock.cpp
PusDistributorMock.cpp
) )

View File

@ -8,7 +8,7 @@ DeviceHandlerMock::DeviceHandlerMock(object_id_t objectId, object_id_t deviceCom
mode = MODE_ON; mode = MODE_ON;
} }
DeviceHandlerMock::~DeviceHandlerMock() {} DeviceHandlerMock::~DeviceHandlerMock() = default;
void DeviceHandlerMock::doStartUp() { setMode(_MODE_TO_ON); } void DeviceHandlerMock::doStartUp() { setMode(_MODE_TO_ON); }

View File

@ -0,0 +1,12 @@
#include "PusDistributorMock.h"
PusDistributorMock::PusDistributorMock() : SystemObject(objects::NO_OBJECT, false) {}
PusDistributorMock::PusDistributorMock(object_id_t registeredId)
: SystemObject(registeredId, true) {}
ReturnValue_t PusDistributorMock::registerService(AcceptsTelecommandsIF *service) {
registerCallCount++;
lastServiceArg = service;
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -0,0 +1,16 @@
#ifndef FSFW_TESTS_PUSDISTRIBUTORMOCK_H
#define FSFW_TESTS_PUSDISTRIBUTORMOCK_H
#include "fsfw/objectmanager/SystemObject.h"
#include "fsfw/tcdistribution/PUSDistributorIF.h"
class PusDistributorMock : public SystemObject, public PUSDistributorIF {
public:
PusDistributorMock();
explicit PusDistributorMock(object_id_t registeredId);
unsigned int registerCallCount = 0;
AcceptsTelecommandsIF* lastServiceArg = nullptr;
ReturnValue_t registerService(AcceptsTelecommandsIF* service) override;
};
#endif // FSFW_TESTS_PUSDISTRIBUTORMOCK_H

View File

@ -39,3 +39,15 @@ bool PsbMock::getAndPopNextSubservice(uint8_t& subservice) {
subserviceQueue.pop(); subserviceQueue.pop();
return true; return true;
} }
PsbParams& PsbMock::getParams() { return psbParams; }
void PsbMock::setStaticPusDistributor(object_id_t pusDistributor) {
PUS_DISTRIBUTOR = pusDistributor;
}
object_id_t PsbMock::getStaticPusDistributor() { return PUS_DISTRIBUTOR; }
void PsbMock::setStaticTmDest(object_id_t tmDest) { PACKET_DESTINATION = tmDest; }
object_id_t PsbMock::getStaticTmDest() { return PACKET_DESTINATION; }

View File

@ -12,6 +12,13 @@ class PsbMock : public PusServiceBase {
std::queue<uint8_t> subserviceQueue; std::queue<uint8_t> subserviceQueue;
unsigned int performServiceCallCnt = 0; unsigned int performServiceCallCnt = 0;
static void setStaticPusDistributor(object_id_t pusDistributor);
static object_id_t getStaticPusDistributor();
static void setStaticTmDest(object_id_t tmDest);
static object_id_t getStaticTmDest();
PsbParams& getParams();
std::pair<bool, ReturnValue_t> handleReqFailPair; std::pair<bool, ReturnValue_t> handleReqFailPair;
std::pair<bool, ReturnValue_t> performServiceFailPair; std::pair<bool, ReturnValue_t> performServiceFailPair;
ReturnValue_t handleRequest(uint8_t subservice) override; ReturnValue_t handleRequest(uint8_t subservice) override;

View File

@ -4,15 +4,18 @@
#include "fsfw/storagemanager/LocalPool.h" #include "fsfw/storagemanager/LocalPool.h"
#include "mocks/AcceptsTmMock.h" #include "mocks/AcceptsTmMock.h"
#include "mocks/CdsShortTimestamperMock.h" #include "mocks/CdsShortTimestamperMock.h"
#include "mocks/InternalErrorReporterMock.h"
#include "mocks/MessageQueueMock.h" #include "mocks/MessageQueueMock.h"
#include "mocks/PusDistributorMock.h"
#include "mocks/PusServiceBaseMock.h" #include "mocks/PusServiceBaseMock.h"
#include "mocks/PusVerificationReporterMock.h" #include "mocks/PusVerificationReporterMock.h"
TEST_CASE("Pus Service Base", "[pus-service-base]") { TEST_CASE("Pus Service Base", "[pus-service-base]") {
uint16_t apid = 2;
auto verificationReporter = PusVerificationReporterMock(); auto verificationReporter = PusVerificationReporterMock();
auto msgQueue = MessageQueueMock(1); auto msgQueue = MessageQueueMock(1);
auto tmReceiver = AcceptsTmMock(2); auto tmReceiver = AcceptsTmMock(2);
auto psbParams = PsbParams(0, 0x02, 17); auto psbParams = PsbParams(0, apid, 17);
LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}}; LocalPool::LocalPoolConfig cfg = {{5, 32}, {2, 64}};
LocalPool pool(objects::NO_OBJECT, cfg); LocalPool pool(objects::NO_OBJECT, cfg);
@ -38,6 +41,9 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") {
SECTION("State") { SECTION("State") {
REQUIRE(psb.getIdentifier() == 17); REQUIRE(psb.getIdentifier() == 17);
REQUIRE(psb.getObjectId() == 0); REQUIRE(psb.getObjectId() == 0);
REQUIRE(psb.getRequestQueue() == msgQueue.getId());
auto psbParamsLocal = psb.getParams();
REQUIRE(psbParamsLocal.errReporter == nullptr);
} }
SECTION("Perform Service") { SECTION("Perform Service") {
@ -87,4 +93,106 @@ TEST_CASE("Pus Service Base", "[pus-service-base]") {
REQUIRE(verifParams.tcPacketId == creator.getPacketIdRaw()); REQUIRE(verifParams.tcPacketId == creator.getPacketIdRaw());
REQUIRE(verifParams.tcPsc == creator.getPacketSeqCtrlRaw()); REQUIRE(verifParams.tcPsc == creator.getPacketSeqCtrlRaw());
} }
SECTION("Invalid Packet Sent") {
tmtcMsg.setStorageId(store_address_t::invalid());
msgQueue.addReceivedMessage(tmtcMsg);
REQUIRE(psb.performOperation(0) == retval::OK);
REQUIRE(verificationReporter.failCallCount() == 1);
auto verifParams = verificationReporter.getNextFailCallParams();
REQUIRE(verifParams.tcPacketId == 0);
REQUIRE(verifParams.tcPsc == 0);
}
SECTION("Set Verif Reporter") {
auto verificationReporter2 = PusVerificationReporterMock();
psb.setVerificationReporter(verificationReporter2);
auto& p = psb.getParams();
REQUIRE(p.verifReporter == &verificationReporter2);
}
SECTION("Set Request Queue") {
auto msgQueueMock = MessageQueueMock(2);
psb.setRequestQueue(msgQueueMock);
auto& p = psb.getParams();
REQUIRE(p.reqQueue == &msgQueueMock);
}
SECTION("Set TM Receiver") {
auto tmReceiver2 = AcceptsTmMock(3);
psb.setTmReceiver(tmReceiver2);
auto& p = psb.getParams();
REQUIRE(p.tmReceiver == &tmReceiver2);
}
SECTION("Set TC Store") {
LocalPool tcStore2(5, cfg);
psb.setTcPool(tcStore2);
auto& p = psb.getParams();
REQUIRE(p.tcPool == &tcStore2);
}
SECTION("Set error reporter") {
auto errReporter = InternalErrorReporterMock();
psb.setErrorReporter(errReporter);
auto& p = psb.getParams();
REQUIRE(p.errReporter == &errReporter);
}
SECTION("Owner Queue") {
// This will cause the initialize function to create a new owner queue
psbParams.reqQueue = nullptr;
psbParams.objectId = 1;
auto mockWithOwnerQueue = PsbMock(psbParams);
REQUIRE(mockWithOwnerQueue.getRequestQueue() == MessageQueueIF::NO_QUEUE);
REQUIRE(mockWithOwnerQueue.initialize() == retval::OK);
REQUIRE(mockWithOwnerQueue.getRequestQueue() != MessageQueueIF::NO_QUEUE);
}
SECTION("TM Store Helper Initializer") {
TmStoreHelper storeHelper(0);
psb.initializeTmStoreHelper(storeHelper);
REQUIRE(storeHelper.getApid() == apid);
}
SECTION("TM Send Helper Initializer") {
TmSendHelper sendHelper;
psb.initializeTmSendHelper(sendHelper);
REQUIRE(sendHelper.getMsgQueue() == &msgQueue);
REQUIRE(sendHelper.getDefaultDestination() == msgQueue.getDefaultDestination());
}
SECTION("TM Send Helper Initializer With Error Reporter") {
TmSendHelper sendHelper;
auto errReporter = InternalErrorReporterMock();
psb.setErrorReporter(errReporter);
psb.initializeTmSendHelper(sendHelper);
REQUIRE(sendHelper.getMsgQueue() == &msgQueue);
REQUIRE(sendHelper.getDefaultDestination() == msgQueue.getDefaultDestination());
REQUIRE(sendHelper.getInternalErrorReporter() == &errReporter);
}
SECTION("Auto Initialize PUS Distributor") {
psbParams.objectId = 1;
object_id_t distributorId = 3;
auto psb2 = PsbMock(psbParams);
auto pusDistrib = PusDistributorMock(distributorId);
PsbMock::setStaticPusDistributor(distributorId);
REQUIRE(PsbMock::getStaticPusDistributor() == distributorId);
REQUIRE(psb2.initialize() == retval::OK);
REQUIRE(pusDistrib.registerCallCount == 1);
REQUIRE(pusDistrib.lastServiceArg == &psb2);
}
SECTION("Auto Initialize Packet Destination") {
psbParams.tmReceiver = nullptr;
psbParams.objectId = 1;
object_id_t destId = 3;
auto psb2 = PsbMock(psbParams);
auto packetDest = AcceptsTmMock(destId, 2);
PsbMock::setStaticTmDest(destId);
REQUIRE(PsbMock::getStaticTmDest() == destId);
REQUIRE(psb2.initialize() == retval::OK);
auto& p = psb2.getParams();
REQUIRE(p.tmReceiver == &packetDest);
}
} }

View File

@ -33,8 +33,9 @@ TEST_CASE("TM Send Helper", "[tm-send-helper]") {
REQUIRE(sendHelper.getDefaultDestination() == destId); REQUIRE(sendHelper.getDefaultDestination() == destId);
sendHelper.setDefaultDestination(destId + 1); sendHelper.setDefaultDestination(destId + 1);
REQUIRE(sendHelper.getDefaultDestination() == destId + 1); REQUIRE(sendHelper.getDefaultDestination() == destId + 1);
sendHelper.setInternalErrorReporter(nullptr); auto errReporter2 = InternalErrorReporterMock();
REQUIRE(sendHelper.getInternalErrorReporter() == nullptr); sendHelper.setInternalErrorReporter(errReporter2);
REQUIRE(sendHelper.getInternalErrorReporter() == &errReporter2);
} }
SECTION("Default CTOR") { SECTION("Default CTOR") {