Merge branch 'mueller/data-wrapper' into mueller/dhb-handle-device-tm
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good
This commit is contained in:
commit
093052604a
@ -10,6 +10,7 @@
|
||||
namespace util {
|
||||
|
||||
struct RawData {
|
||||
RawData() = default;
|
||||
const uint8_t* data = nullptr;
|
||||
size_t len = 0;
|
||||
};
|
||||
@ -17,8 +18,8 @@ struct RawData {
|
||||
enum DataTypes { NONE, RAW, SERIALIZABLE };
|
||||
|
||||
union DataUnion {
|
||||
RawData raw;
|
||||
SerializeIF* serializable = nullptr;
|
||||
RawData raw{};
|
||||
SerializeIF* serializable;
|
||||
};
|
||||
|
||||
struct DataWrapper {
|
||||
@ -36,9 +37,8 @@ struct DataWrapper {
|
||||
}
|
||||
|
||||
[[nodiscard]] bool isNull() const {
|
||||
if (type == DataTypes::RAW and dataUnion.raw.data == nullptr or
|
||||
(type == DataTypes::SERIALIZABLE and dataUnion.serializable == nullptr) or
|
||||
(type == DataTypes::NONE)) {
|
||||
if ((type == DataTypes::NONE) or (type == DataTypes::RAW and dataUnion.raw.data == nullptr) or
|
||||
(type == DataTypes::SERIALIZABLE and dataUnion.serializable == nullptr)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -1,3 +1,4 @@
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||
testUnsignedByteField.cpp
|
||||
testDataWrapper.cpp
|
||||
)
|
||||
|
32
unittests/util/testDataWrapper.cpp
Normal file
32
unittests/util/testDataWrapper.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#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());
|
||||
REQUIRE(wrapper.type == util::DataTypes::NONE);
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") {
|
||||
TEST_CASE("Unsigned Byte Field", "[util]") {
|
||||
auto testByteField = UnsignedByteField<uint32_t>(10);
|
||||
auto u32ByteField = U32ByteField(10);
|
||||
auto u16ByteField = U16ByteField(5);
|
||||
|
Loading…
Reference in New Issue
Block a user