2024-11-06 14:18:32 +01:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
|
|
|
|
#include "fsfw/serialize/SerializableList.h"
|
|
|
|
#include "fsfw/serialize/SerializableListElement.h"
|
|
|
|
|
|
|
|
using namespace serialize;
|
|
|
|
|
|
|
|
class ExampleSet0 : public List {
|
|
|
|
public:
|
2024-11-13 11:45:26 +01:00
|
|
|
LVar<uint8_t> val0{*this};
|
|
|
|
LVar<uint32_t> val1{*this};
|
|
|
|
LVec<uint16_t, 3> val2{*this};
|
2024-11-06 14:18:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
using namespace returnvalue;
|
|
|
|
|
|
|
|
TEST_CASE("Serial List", "[serialize]") {
|
|
|
|
ExampleSet0 set0;
|
|
|
|
uint8_t buf[1024]{};
|
|
|
|
size_t serSize = 0;
|
|
|
|
size_t dummy = 0;
|
|
|
|
SECTION("serialization default") {
|
|
|
|
uint8_t* ptr = buf;
|
|
|
|
CHECK(set0.getSerializedSize() == 11);
|
|
|
|
const ReturnValue_t result =
|
|
|
|
set0.serialize(&ptr, &serSize, sizeof(buf), SerializeIF::Endianness::NETWORK);
|
|
|
|
CHECK(result == returnvalue::OK);
|
|
|
|
CHECK(ptr == buf + 11);
|
|
|
|
CHECK(buf[0] == 0);
|
|
|
|
uint32_t u32Val = 0;
|
|
|
|
CHECK(SerializeAdapter::deSerialize(&u32Val, buf + 1, &dummy,
|
|
|
|
SerializeIF::Endianness::NETWORK) == OK);
|
|
|
|
CHECK(u32Val == 0);
|
|
|
|
uint16_t u16Val = 0;
|
|
|
|
for (uint32_t i = 0; i < 3; i++) {
|
|
|
|
CHECK(SerializeAdapter::deSerialize(&u16Val, buf + 5, &dummy,
|
|
|
|
SerializeIF::Endianness::NETWORK) == OK);
|
|
|
|
CHECK(u16Val == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("serialization with values") {
|
|
|
|
uint8_t* ptr = buf;
|
|
|
|
set0.val0 = 240;
|
|
|
|
set0.val1 = 0x1f1f1f1f;
|
|
|
|
set0.val2[0] = 0x1f1f;
|
|
|
|
set0.val2[1] = 0xf1f1;
|
|
|
|
set0.val2[2] = 0x4242;
|
|
|
|
const ReturnValue_t result =
|
|
|
|
set0.serialize(&ptr, &serSize, sizeof(buf), SerializeIF::Endianness::NETWORK);
|
|
|
|
CHECK(result == returnvalue::OK);
|
|
|
|
dummy = set0.getSerializedSize();
|
|
|
|
CHECK(ptr == buf + 11);
|
|
|
|
CHECK(buf[0] == 240);
|
|
|
|
const uint8_t* cPtr = buf + 1;
|
|
|
|
uint32_t u32Val = 0;
|
|
|
|
CHECK(SerializeAdapter::deSerialize(&u32Val, &cPtr, &dummy, SerializeIF::Endianness::NETWORK) ==
|
|
|
|
OK);
|
|
|
|
CHECK(u32Val == 0x1f1f1f1f);
|
|
|
|
uint16_t u16Val = 0;
|
|
|
|
CHECK(SerializeAdapter::deSerialize(&u16Val, &cPtr, &dummy, SerializeIF::Endianness::NETWORK) ==
|
|
|
|
OK);
|
|
|
|
CHECK(u16Val == 0x1f1f);
|
|
|
|
CHECK(SerializeAdapter::deSerialize(&u16Val, &cPtr, &dummy, SerializeIF::Endianness::NETWORK) ==
|
|
|
|
OK);
|
|
|
|
CHECK(u16Val == 0xf1f1);
|
|
|
|
CHECK(SerializeAdapter::deSerialize(&u16Val, &cPtr, &dummy, SerializeIF::Endianness::NETWORK) ==
|
|
|
|
OK);
|
|
|
|
CHECK(u16Val == 0x4242);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("deserialization with values") {
|
|
|
|
uint8_t* ptr = buf;
|
|
|
|
set0.val0 = 240;
|
|
|
|
set0.val1 = 0x1f1f1f1f;
|
|
|
|
set0.val2[0] = 0x1f1f;
|
|
|
|
set0.val2[1] = 0xf1f1;
|
|
|
|
set0.val2[2] = 0x4242;
|
|
|
|
const ReturnValue_t result =
|
|
|
|
set0.serialize(&ptr, &serSize, sizeof(buf), SerializeIF::Endianness::NETWORK);
|
|
|
|
CHECK(result == returnvalue::OK);
|
|
|
|
const uint8_t* cPtr = buf;
|
|
|
|
dummy = set0.getSerializedSize();
|
|
|
|
ExampleSet0 deserSet;
|
|
|
|
CHECK(deserSet.deSerialize(&cPtr, &dummy, SerializeIF::Endianness::NETWORK) == returnvalue::OK);
|
|
|
|
|
|
|
|
CHECK(deserSet.val0.get() == 240);
|
|
|
|
CHECK(deserSet.val1.get() == 0x1f1f1f1f);
|
|
|
|
CHECK(deserSet.val2[0] == 0x1f1f);
|
|
|
|
CHECK(deserSet.val2[1] == 0xf1f1);
|
|
|
|
CHECK(deserSet.val2[2] == 0x4242);
|
|
|
|
CHECK(dummy == 0);
|
|
|
|
}
|
|
|
|
}
|