2022-07-22 16:06:31 +02:00
|
|
|
#ifndef FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H
|
|
|
|
#define FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
2022-07-25 10:50:52 +02:00
|
|
|
#include "fsfw/timemanager/TimeReaderIF.h"
|
2022-09-05 14:44:35 +02:00
|
|
|
#include "fsfw/timemanager/TimeWriterIF.h"
|
2022-07-22 16:06:31 +02:00
|
|
|
|
2022-09-05 14:44:35 +02:00
|
|
|
class CdsShortTimestamperMock : public TimeWriterIF, public TimeReaderIF {
|
2022-07-22 16:06:31 +02:00
|
|
|
public:
|
|
|
|
unsigned int serializeCallCount = 0;
|
2022-07-22 18:22:35 +02:00
|
|
|
unsigned int deserializeCallCount = 0;
|
2022-08-16 01:08:26 +02:00
|
|
|
ReturnValue_t lastDeserializeResult = returnvalue::OK;
|
|
|
|
ReturnValue_t lastSerializeResult = returnvalue::OK;
|
2022-07-22 16:06:31 +02:00
|
|
|
unsigned int getSizeCallCount = 0;
|
2022-07-22 18:31:00 +02:00
|
|
|
bool nextSerFails = false;
|
2022-08-16 01:08:26 +02:00
|
|
|
ReturnValue_t serFailRetval = returnvalue::FAILED;
|
2022-07-22 18:31:00 +02:00
|
|
|
bool nextDeserFails = false;
|
2022-08-16 01:08:26 +02:00
|
|
|
ReturnValue_t deserFailRetval = returnvalue::FAILED;
|
2022-07-22 16:06:31 +02:00
|
|
|
std::array<uint8_t, 7> valueToStamp{};
|
|
|
|
|
|
|
|
CdsShortTimestamperMock() = default;
|
|
|
|
|
|
|
|
explicit CdsShortTimestamperMock(std::array<uint8_t, 7> valueToStamp)
|
|
|
|
: valueToStamp(valueToStamp) {}
|
|
|
|
|
|
|
|
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
|
|
|
Endianness streamEndianness) const override {
|
|
|
|
auto &thisNonConst = const_cast<CdsShortTimestamperMock &>(*this);
|
|
|
|
thisNonConst.serializeCallCount += 1;
|
2022-07-22 18:31:00 +02:00
|
|
|
if (nextSerFails) {
|
|
|
|
return serFailRetval;
|
|
|
|
}
|
2022-07-22 16:06:31 +02:00
|
|
|
if (*size + getSerializedSize() > maxSize) {
|
|
|
|
thisNonConst.lastSerializeResult = SerializeIF::BUFFER_TOO_SHORT;
|
|
|
|
return lastSerializeResult;
|
|
|
|
}
|
|
|
|
std::copy(valueToStamp.begin(), valueToStamp.end(), *buffer);
|
2022-08-16 01:08:26 +02:00
|
|
|
thisNonConst.lastSerializeResult = returnvalue::OK;
|
2022-07-22 16:06:31 +02:00
|
|
|
*buffer += getSerializedSize();
|
|
|
|
*size += getSerializedSize();
|
|
|
|
return lastSerializeResult;
|
|
|
|
}
|
|
|
|
[[nodiscard]] size_t getSerializedSize() const override {
|
|
|
|
auto &thisNonConst = const_cast<CdsShortTimestamperMock &>(*this);
|
|
|
|
thisNonConst.getSizeCallCount += 1;
|
|
|
|
return valueToStamp.size();
|
|
|
|
}
|
|
|
|
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
|
|
|
Endianness streamEndianness) override {
|
2022-07-22 18:22:35 +02:00
|
|
|
deserializeCallCount += 1;
|
2022-07-22 18:31:00 +02:00
|
|
|
if (nextDeserFails) {
|
|
|
|
return deserFailRetval;
|
|
|
|
}
|
2022-07-22 18:22:35 +02:00
|
|
|
if (*size < 7) {
|
|
|
|
lastDeserializeResult = SerializeIF::STREAM_TOO_SHORT;
|
|
|
|
return lastDeserializeResult;
|
|
|
|
}
|
|
|
|
std::copy(*buffer, *buffer + getSerializedSize(), valueToStamp.begin());
|
|
|
|
return lastDeserializeResult;
|
2022-07-22 16:06:31 +02:00
|
|
|
}
|
2022-07-22 18:22:35 +02:00
|
|
|
|
2022-07-22 16:06:31 +02:00
|
|
|
[[nodiscard]] size_t getTimestampSize() const override { return getSerializedSize(); }
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
serializeCallCount = 0;
|
|
|
|
getSizeCallCount = 0;
|
2022-07-22 18:31:00 +02:00
|
|
|
deserializeCallCount = 0;
|
|
|
|
nextSerFails = false;
|
|
|
|
nextDeserFails = false;
|
2022-08-16 01:08:26 +02:00
|
|
|
lastSerializeResult = returnvalue::OK;
|
|
|
|
lastDeserializeResult = returnvalue::OK;
|
|
|
|
deserFailRetval = returnvalue::FAILED;
|
|
|
|
serFailRetval = returnvalue::FAILED;
|
2022-07-22 16:06:31 +02:00
|
|
|
}
|
2022-07-22 18:31:00 +02:00
|
|
|
|
2022-07-22 18:22:35 +02:00
|
|
|
timeval &getTime() override { return dummyTime; }
|
2022-07-22 16:06:31 +02:00
|
|
|
|
|
|
|
private:
|
2022-07-22 18:22:35 +02:00
|
|
|
timeval dummyTime{};
|
2022-07-22 16:06:31 +02:00
|
|
|
};
|
|
|
|
#endif // FSFW_TESTS_CDSSHORTTIMESTAMPERMOCK_H
|