fsfw/tests/src/fsfw_tests/unit/action/TestActionHelper.h

76 lines
2.1 KiB
C
Raw Normal View History

2020-12-03 14:44:11 +01:00
#ifndef UNITTEST_HOSTED_TESTACTIONHELPER_H_
#define UNITTEST_HOSTED_TESTACTIONHELPER_H_
#include <fsfw/action/HasActionsIF.h>
2022-06-29 23:36:45 +02:00
#include <fsfw/action/Parameter.h>
#include <fsfw/action/TemplateAction.h>
#include <fsfw/introspection/Enum.h>
2020-12-03 14:44:11 +01:00
#include <fsfw/ipc/MessageQueueIF.h>
2022-02-02 10:29:30 +01:00
2020-12-03 14:44:11 +01:00
#include <cstring>
2022-02-02 10:29:30 +01:00
#include "fsfw_tests/unit/CatchDefinitions.h"
2020-12-03 14:44:11 +01:00
2022-06-29 23:36:45 +02:00
class ActionHelperOwnerMockBase;
FSFW_ENUM(TestActions, ActionId_t, ((TEST_ACTION, "Test Action")))
class TestAction : public TemplateAction < ActionHelperOwnerMockBase, TestAction, TestActions> {
public:
TestAction(ActionHelperOwnerMockBase* owner) : TemplateAction(owner, TestActions::TEST_ACTION) {}
Parameter<uint8_t> p1 = Parameter<uint8_t>::createParameter(this, "An uint8_t");
Parameter<uint8_t> p2 = Parameter<uint8_t>::createParameter(this, "An uint8_t");
Parameter<uint8_t> p3 = Parameter<uint8_t>::createParameter(this, "An uint8_t");
};
2022-02-02 10:29:30 +01:00
class ActionHelperOwnerMockBase : public HasActionsIF {
public:
bool getCommandQueueCalled = false;
bool executeActionCalled = false;
static const size_t MAX_SIZE = 3;
uint8_t buffer[MAX_SIZE] = {0, 0, 0};
size_t size = 0;
2022-06-29 23:36:45 +02:00
ActionHelperOwnerMockBase(MessageQueueIF* useThisQueue) : actionHelper(this, useThisQueue) {}
2022-02-02 10:29:30 +01:00
MessageQueueId_t getCommandQueue() const override { return tconst::testQueueId; }
2022-06-29 23:36:45 +02:00
ActionHelper* getActionHelper() override { return &actionHelper; }
2022-07-20 16:59:42 +02:00
ReturnValue_t executeAction(Action* action) override {
2022-02-02 10:29:30 +01:00
executeActionCalled = true;
if (size > MAX_SIZE) {
return 0xAFFE;
}
this->size = size;
2022-06-29 23:36:45 +02:00
return action->handle();
}
ReturnValue_t handleAction(TestAction *action){
executeActionCalled = true;
buffer[0] = action->p1;
buffer[1] = action->p2;
buffer[2] = action->p3;
2022-02-02 10:29:30 +01:00
return HasReturnvaluesIF::RETURN_OK;
}
void clearBuffer() {
this->size = 0;
for (size_t i = 0; i < MAX_SIZE; i++) {
buffer[i] = 0;
}
}
2022-06-29 23:36:45 +02:00
void getBuffer(const uint8_t** ptr) {
2022-02-02 10:29:30 +01:00
if (ptr != nullptr) {
*ptr = buffer;
}
}
2022-06-29 23:36:45 +02:00
private:
ActionHelper actionHelper;
TestAction testAction = TestAction(this);
2022-02-02 10:29:30 +01:00
};
2020-12-03 14:44:11 +01:00
#endif /* UNITTEST_TESTFW_NEWTESTS_TESTACTIONHELPER_H_ */