fsfw/unittests/datapool/testDataset.cpp

86 lines
2.6 KiB
C++

#include <fsfw/housekeeping/Dataset.h>
#include <fsfw/housekeeping/DatasetElement.h>
#include <fsfw/serialize/SerializeElement.h>
#include <catch2/catch_test_macros.hpp>
constexpr auto TEST_ID = dp::structure_id_t(1, 2);
class TestDatasetSmall : public hk::Dataset {
public:
TestDatasetSmall() : hk::Dataset(TEST_ID, false) {}
hk::lvar_u8 test0{*this};
hk::lvar_u32 test1{*this};
};
class TestDatasetLarger : public hk::Dataset {
public:
TestDatasetLarger() : hk::Dataset(TEST_ID, false) {}
hk::lvar_u8 test0{*this};
hk::lvar_u32 test1{*this};
hk::lvar_u16 test2{*this};
hk::lvar_i32 test3{*this};
hk::lvar_f32 test4{*this};
hk::lvar_f64 test5{*this};
hk::lvar_u8 test6{*this};
hk::lvar_i16 test7{*this};
hk::lvec_u16<2> test8{*this};
};
TEST_CASE("Pool Dataset Test", "[datapool]") {
TestDatasetSmall dataset;
CHECK(dataset.getStructureId() == TEST_ID);
CHECK(!dataset.test0.isValid());
dataset.test0.setValid(true);
CHECK(dataset.test0.isValid());
SECTION("Pool Dataset Serialization Test 1") {
uint8_t buf[64]{};
dataset.test0 = 55;
dataset.test1 = 502392;
size_t serLen = 0;
CHECK(dataset.serialize(buf, serLen, sizeof(buf), SerializeIF::Endianness::NETWORK) ==
returnvalue::OK);
CHECK(buf[0] == 55);
CHECK(serLen == 5);
uint32_t readBack = 0;
size_t dummy = 0;
CHECK(SerializeAdapter::deSerialize(&readBack, buf + 1, &dummy,
SerializeIF::Endianness::NETWORK) == returnvalue::OK);
CHECK(readBack == 502392);
CHECK(buf[5] == 0);
}
SECTION("Pool Dataset Serialization With Validity") {
uint8_t buf[64]{};
dataset.test0 = 55;
dataset.test1 = 502392;
dataset.test0.setValid(true);
dataset.test1.setValid(true);
size_t serLen = 0;
uint8_t* dataPtr = buf;
dataset.serializeWithValidityBlob = true;
CHECK(dataset.getSerializedSize() == 6);
CHECK(dataset.serialize(&dataPtr, &serLen, sizeof(buf), SerializeIF::Endianness::NETWORK) ==
returnvalue::OK);
CHECK(buf[5] == 0b11000000);
}
SECTION("Larger Pool Dataset Serialization With Validity") {
uint8_t buf[64]{};
TestDatasetLarger datasetLarge;
datasetLarge.setChildrenValidity(true);
size_t serLen = 0;
uint8_t* dataPtr = buf;
datasetLarge.serializeWithValidityBlob = true;
CHECK(datasetLarge.serialize(&dataPtr, &serLen, sizeof(buf),
SerializeIF::Endianness::NETWORK) == returnvalue::OK);
CHECK(serLen == 32);
CHECK(buf[30] == 0b11111111);
CHECK(buf[31] == 0b10000000);
CHECK(buf[32] == 0);
}
}