basic data wrapper unittests
This commit is contained in:
parent
c756297e5c
commit
bdd79d060d
@ -10,6 +10,7 @@
|
|||||||
namespace util {
|
namespace util {
|
||||||
|
|
||||||
struct RawData {
|
struct RawData {
|
||||||
|
RawData() = default;
|
||||||
const uint8_t* data = nullptr;
|
const uint8_t* data = nullptr;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
};
|
};
|
||||||
@ -17,8 +18,8 @@ struct RawData {
|
|||||||
enum DataTypes { NONE, RAW, SERIALIZABLE };
|
enum DataTypes { NONE, RAW, SERIALIZABLE };
|
||||||
|
|
||||||
union DataUnion {
|
union DataUnion {
|
||||||
RawData raw;
|
RawData raw{};
|
||||||
SerializeIF* serializable = nullptr;
|
SerializeIF* serializable;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DataWrapper {
|
struct DataWrapper {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||||
testUnsignedByteField.cpp
|
testUnsignedByteField.cpp
|
||||||
|
testDataWrapper.cpp
|
||||||
)
|
)
|
||||||
|
31
unittests/util/testDataWrapper.cpp
Normal file
31
unittests/util/testDataWrapper.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include <array>
|
||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
|
||||||
|
#include "fsfw/util/dataWrapper.h"
|
||||||
|
#include "mocks/SimpleSerializable.h"
|
||||||
|
|
||||||
|
TEST_CASE("Data Wrapper", "[util]") {
|
||||||
|
util::DataWrapper wrapper;
|
||||||
|
SECTION("State") {
|
||||||
|
REQUIRE(wrapper.isNull());
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Set Raw Data") {
|
||||||
|
REQUIRE(wrapper.isNull());
|
||||||
|
std::array<uint8_t, 4> data = {1, 2, 3, 4};
|
||||||
|
wrapper.setRawData({data.data(), data.size()});
|
||||||
|
REQUIRE(not wrapper.isNull());
|
||||||
|
REQUIRE(wrapper.type == util::DataTypes::RAW);
|
||||||
|
REQUIRE(wrapper.dataUnion.raw.data == data.data());
|
||||||
|
REQUIRE(wrapper.dataUnion.raw.len == data.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Simple Serializable") {
|
||||||
|
REQUIRE(wrapper.isNull());
|
||||||
|
SimpleSerializable serializable;
|
||||||
|
wrapper.setSerializable(serializable);
|
||||||
|
REQUIRE(not wrapper.isNull());
|
||||||
|
REQUIRE(wrapper.type == util::DataTypes::SERIALIZABLE);
|
||||||
|
REQUIRE(wrapper.dataUnion.serializable == &serializable);
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "fsfw/util/UnsignedByteField.h"
|
#include "fsfw/util/UnsignedByteField.h"
|
||||||
|
|
||||||
TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") {
|
TEST_CASE("Unsigned Byte Field", "[util]") {
|
||||||
auto testByteField = UnsignedByteField<uint32_t>(10);
|
auto testByteField = UnsignedByteField<uint32_t>(10);
|
||||||
auto u32ByteField = U32ByteField(10);
|
auto u32ByteField = U32ByteField(10);
|
||||||
auto u16ByteField = U16ByteField(5);
|
auto u16ByteField = U16ByteField(5);
|
||||||
|
Loading…
Reference in New Issue
Block a user