From c756297e5c1ece6a2e22aa036c9a8c1d5a2e435b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 30 Aug 2022 13:39:44 +0200 Subject: [PATCH 1/3] data wrapper update --- src/fsfw/util/dataWrapper.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/fsfw/util/dataWrapper.h b/src/fsfw/util/dataWrapper.h index 5ae2c043..8bb373e6 100644 --- a/src/fsfw/util/dataWrapper.h +++ b/src/fsfw/util/dataWrapper.h @@ -36,9 +36,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; From bdd79d060df5ddde24da71b3a7df83ffbf486be9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 30 Aug 2022 14:02:58 +0200 Subject: [PATCH 2/3] basic data wrapper unittests --- src/fsfw/util/dataWrapper.h | 5 ++-- unittests/util/CMakeLists.txt | 1 + unittests/util/testDataWrapper.cpp | 31 ++++++++++++++++++++++++ unittests/util/testUnsignedByteField.cpp | 2 +- 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 unittests/util/testDataWrapper.cpp diff --git a/src/fsfw/util/dataWrapper.h b/src/fsfw/util/dataWrapper.h index 8bb373e6..440f9501 100644 --- a/src/fsfw/util/dataWrapper.h +++ b/src/fsfw/util/dataWrapper.h @@ -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 { diff --git a/unittests/util/CMakeLists.txt b/unittests/util/CMakeLists.txt index d4caa4d5..dd9f6dc1 100644 --- a/unittests/util/CMakeLists.txt +++ b/unittests/util/CMakeLists.txt @@ -1,3 +1,4 @@ target_sources(${FSFW_TEST_TGT} PRIVATE testUnsignedByteField.cpp + testDataWrapper.cpp ) diff --git a/unittests/util/testDataWrapper.cpp b/unittests/util/testDataWrapper.cpp new file mode 100644 index 00000000..5a6b26d7 --- /dev/null +++ b/unittests/util/testDataWrapper.cpp @@ -0,0 +1,31 @@ +#include +#include + +#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 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); + } +} \ No newline at end of file diff --git a/unittests/util/testUnsignedByteField.cpp b/unittests/util/testUnsignedByteField.cpp index df1ff483..58a87a7d 100644 --- a/unittests/util/testUnsignedByteField.cpp +++ b/unittests/util/testUnsignedByteField.cpp @@ -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(10); auto u32ByteField = U32ByteField(10); auto u16ByteField = U16ByteField(5); From 192255df1cc9b75559d9bd57d44f467bc49a3b83 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 30 Aug 2022 14:03:33 +0200 Subject: [PATCH 3/3] additional test --- unittests/util/testDataWrapper.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/unittests/util/testDataWrapper.cpp b/unittests/util/testDataWrapper.cpp index 5a6b26d7..14ba287a 100644 --- a/unittests/util/testDataWrapper.cpp +++ b/unittests/util/testDataWrapper.cpp @@ -8,6 +8,7 @@ TEST_CASE("Data Wrapper", "[util]") { util::DataWrapper wrapper; SECTION("State") { REQUIRE(wrapper.isNull()); + REQUIRE(wrapper.type == util::DataTypes::NONE); } SECTION("Set Raw Data") {