completed baseline PUS TM unittests
This commit is contained in:
parent
b350018cad
commit
cb05329dd9
@ -12,6 +12,10 @@ class CdsShortTimestamperMock : public TimeStamperIF, public TimeReaderIF {
|
||||
ReturnValue_t lastDeserializeResult = HasReturnvaluesIF::RETURN_OK;
|
||||
ReturnValue_t lastSerializeResult = HasReturnvaluesIF::RETURN_OK;
|
||||
unsigned int getSizeCallCount = 0;
|
||||
bool nextSerFails = false;
|
||||
ReturnValue_t serFailRetval = HasReturnvaluesIF::RETURN_FAILED;
|
||||
bool nextDeserFails = false;
|
||||
ReturnValue_t deserFailRetval = HasReturnvaluesIF::RETURN_FAILED;
|
||||
std::array<uint8_t, 7> valueToStamp{};
|
||||
|
||||
CdsShortTimestamperMock() = default;
|
||||
@ -23,6 +27,9 @@ class CdsShortTimestamperMock : public TimeStamperIF, public TimeReaderIF {
|
||||
Endianness streamEndianness) const override {
|
||||
auto &thisNonConst = const_cast<CdsShortTimestamperMock &>(*this);
|
||||
thisNonConst.serializeCallCount += 1;
|
||||
if (nextSerFails) {
|
||||
return serFailRetval;
|
||||
}
|
||||
if (*size + getSerializedSize() > maxSize) {
|
||||
thisNonConst.lastSerializeResult = SerializeIF::BUFFER_TOO_SHORT;
|
||||
return lastSerializeResult;
|
||||
@ -41,6 +48,9 @@ class CdsShortTimestamperMock : public TimeStamperIF, public TimeReaderIF {
|
||||
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) override {
|
||||
deserializeCallCount += 1;
|
||||
if (nextDeserFails) {
|
||||
return deserFailRetval;
|
||||
}
|
||||
if (*size < 7) {
|
||||
lastDeserializeResult = SerializeIF::STREAM_TOO_SHORT;
|
||||
return lastDeserializeResult;
|
||||
@ -55,7 +65,15 @@ class CdsShortTimestamperMock : public TimeStamperIF, public TimeReaderIF {
|
||||
void reset() {
|
||||
serializeCallCount = 0;
|
||||
getSizeCallCount = 0;
|
||||
deserializeCallCount = 0;
|
||||
nextSerFails = false;
|
||||
nextDeserFails = false;
|
||||
lastSerializeResult = HasReturnvaluesIF::RETURN_OK;
|
||||
lastDeserializeResult = HasReturnvaluesIF::RETURN_OK;
|
||||
deserFailRetval = HasReturnvaluesIF::RETURN_FAILED;
|
||||
serFailRetval = HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t readTimeStamp(const uint8_t *buffer, size_t maxSize) override {
|
||||
return deSerialize(&buffer, &maxSize, SerializeIF::Endianness::NETWORK);
|
||||
}
|
||||
|
@ -91,4 +91,18 @@ TEST_CASE("PUS TM Reader", "[pus-tm-reader]") {
|
||||
REQUIRE(roData[1] == 2);
|
||||
REQUIRE(roData[2] == 3);
|
||||
}
|
||||
|
||||
SECTION("Invalid stream lengths") {
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
for (size_t i = 0; i < serLen - 1; i++) {
|
||||
REQUIRE(reader.setReadOnlyData(buf.data(), i) == SerializeIF::STREAM_TOO_SHORT);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Reading timestamp fails") {
|
||||
timeStamperAndReader.nextDeserFails = true;
|
||||
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_FAILED);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user