fsfw/unittests/tmtcpacket/testZcTmWriter.cpp

42 lines
1.6 KiB
C++
Raw Normal View History

2022-07-28 12:52:20 +02:00
#include <catch2/catch_test_macros.hpp>
2022-07-28 13:24:50 +02:00
#include "fsfw/globalfunctions/CRC.h"
2022-07-28 12:52:20 +02:00
#include "fsfw/tmtcpacket/pus/tm.h"
#include "fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h"
#include "mocks/CdsShortTimestamperMock.h"
TEST_CASE("TM ZC Helper", "[tm-zc-helper]") {
auto packetId = PacketId(ccsds::PacketType::TC, true, 0xef);
auto spParams =
SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 22), 0x00);
auto timeStamper = CdsShortTimestamperMock();
auto pusTmParams = PusTmParams(17, 2, &timeStamper);
timeStamper.valueToStamp = {1, 2, 3, 4, 5, 6, 7};
PusTmCreator creator(spParams, pusTmParams);
std::array<uint8_t, 32> buf{};
uint8_t* dataPtr = buf.data();
size_t serLen = 0;
2022-07-28 13:24:50 +02:00
SECTION("No Crash For Uninitialized Object") {
2022-08-16 01:08:26 +02:00
REQUIRE(creator.serializeBe(dataPtr, serLen, buf.size()) == returnvalue::OK);
2022-07-28 13:24:50 +02:00
PusTmZeroCopyWriter writer(timeStamper, dataPtr, serLen);
REQUIRE(writer.getSequenceCount() == 22);
writer.setSequenceCount(23);
// Can't set anything, parse function was not called
REQUIRE(writer.getSequenceCount() == 22);
writer.updateErrorControl();
}
2022-07-28 12:52:20 +02:00
SECTION("Basic") {
2022-08-16 01:08:26 +02:00
REQUIRE(creator.serializeBe(dataPtr, serLen, buf.size()) == returnvalue::OK);
2022-07-28 13:24:50 +02:00
PusTmZeroCopyWriter writer(timeStamper, dataPtr, serLen);
2022-08-16 01:08:26 +02:00
REQUIRE(writer.parseDataWithoutCrcCheck() == returnvalue::OK);
2022-07-28 13:24:50 +02:00
REQUIRE(writer.getSequenceCount() == 22);
writer.setSequenceCount(23);
REQUIRE(writer.getSequenceCount() == 23);
// CRC is invalid now
REQUIRE(CRC::crc16ccitt(dataPtr, serLen) != 0);
writer.updateErrorControl();
REQUIRE(CRC::crc16ccitt(dataPtr, serLen) == 0);
2022-07-28 12:52:20 +02:00
}
}