basic data wrapper unittests
All checks were successful
fsfw/fsfw/pipeline/pr-development This commit looks good

This commit is contained in:
Robin Müller 2022-08-30 14:02:58 +02:00
parent c756297e5c
commit bdd79d060d
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
4 changed files with 36 additions and 3 deletions

View File

@ -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 {

View File

@ -1,3 +1,4 @@
target_sources(${FSFW_TEST_TGT} PRIVATE
testUnsignedByteField.cpp
testDataWrapper.cpp
)

View 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);
}
}

View File

@ -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);