fix unit test

This commit is contained in:
Robin Müller 2022-05-30 12:12:07 +02:00 committed by Gitea
parent 3f9e459f48
commit 92ec24352f
4 changed files with 23 additions and 21 deletions

View File

@ -63,3 +63,11 @@ ReturnValue_t PeriodicTaskBase::addComponent(ExecutableObjectIF* object, uint8_t
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t PeriodicTaskBase::addComponent(object_id_t object) {
return addComponent(object, 0);
}
ReturnValue_t PeriodicTaskBase::addComponent(ExecutableObjectIF *object) {
return addComponent(object, 0);
}

View File

@ -17,6 +17,9 @@ class PeriodicTaskBase : public PeriodicTaskIF {
ReturnValue_t addComponent(object_id_t object, uint8_t opCode) override;
ReturnValue_t addComponent(ExecutableObjectIF* object, uint8_t opCode) override;
ReturnValue_t addComponent(object_id_t object) override;
ReturnValue_t addComponent(ExecutableObjectIF* object) override;
[[nodiscard]] uint32_t getPeriodMs() const override;
[[nodiscard]] bool isEmpty() const override;

View File

@ -16,7 +16,7 @@
#include "fsfw_tests/unit/mocks/PeriodicTaskIFMock.h"
TEST_CASE("Internal Error Reporter", "[TestInternalError]") {
PeriodicTaskMock task(10);
PeriodicTaskMock task(10, nullptr);
ObjectManagerIF* manager = ObjectManager::instance();
if (manager == nullptr) {
FAIL();
@ -27,6 +27,8 @@ TEST_CASE("Internal Error Reporter", "[TestInternalError]") {
FAIL();
}
task.addComponent(objects::INTERNAL_ERROR_REPORTER);
// This calls the initializeAfterTaskCreation function
task.startTask();
MessageQueueIF* testQueue = QueueFactory::instance()->createMessageQueue(1);
MessageQueueIF* hkQueue = QueueFactory::instance()->createMessageQueue(1);
internalErrorReporter->getSubscriptionInterface()->subscribeForSetUpdateMessage(

View File

@ -2,36 +2,25 @@
#define FSFW_UNITTEST_TESTS_MOCKS_PERIODICTASKMOCK_H_
#include <fsfw/tasks/ExecutableObjectIF.h>
#include <fsfw/tasks/PeriodicTaskIF.h>
#include <fsfw/tasks/PeriodicTaskBase.h>
class PeriodicTaskMock : public PeriodicTaskIF {
class PeriodicTaskMock : public PeriodicTaskBase {
public:
PeriodicTaskMock(uint32_t period = 5) : period(period) {}
/**
* @brief A virtual destructor as it is mandatory for interfaces.
*/
PeriodicTaskMock(TaskPeriod period, TaskDeadlineMissedFunction dlmFunc)
: PeriodicTaskBase(period, dlmFunc) {}
virtual ~PeriodicTaskMock() {}
/**
* @brief With the startTask method, a created task can be started
* for the first time.
*/
virtual ReturnValue_t startTask() override { return HasReturnvaluesIF::RETURN_OK; };
virtual ReturnValue_t addComponent(object_id_t object) override {
ExecutableObjectIF* executableObject =
ObjectManager::instance()->get<ExecutableObjectIF>(objects::INTERNAL_ERROR_REPORTER);
if (executableObject == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
executableObject->setTaskIF(this);
executableObject->initializeAfterTaskCreation();
virtual ReturnValue_t startTask() override {
initObjsAfterTaskCreation();
return HasReturnvaluesIF::RETURN_OK;
};
virtual ReturnValue_t sleepFor(uint32_t ms) override { return HasReturnvaluesIF::RETURN_OK; };
virtual uint32_t getPeriodMs() const override { return period; };
uint32_t period;
};
#endif // FSFW_UNITTEST_TESTS_MOCKS_PERIODICTASKMOCK_H_