fsfw/unittests/util/testDataWrapper.cpp

59 lines
1.7 KiB
C++
Raw Normal View History

2022-08-30 14:02:58 +02:00
#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());
2022-08-30 14:03:33 +02:00
REQUIRE(wrapper.type == util::DataTypes::NONE);
2022-08-30 14:02:58 +02:00
}
SECTION("Set Raw Data") {
2022-08-30 16:02:50 +02:00
util::DataWrapper* instance = &wrapper;
bool deleteInst = false;
2022-08-30 14:02:58 +02:00
REQUIRE(wrapper.isNull());
std::array<uint8_t, 4> data = {1, 2, 3, 4};
2022-08-30 16:02:50 +02:00
SECTION("Setter") {
wrapper.setRawData({data.data(), data.size()});
}
SECTION("Direct Construction Pair") {
instance = new util::DataWrapper(util::BufPair(data.data(), data.size()));
deleteInst = true;
}
SECTION("Direct Construction Single Args") {
instance = new util::DataWrapper(data.data(), data.size());
deleteInst = true;
}
REQUIRE(not instance->isNull());
REQUIRE(instance->type == util::DataTypes::RAW);
REQUIRE(instance->dataUnion.raw.data == data.data());
REQUIRE(instance->dataUnion.raw.len == data.size());
if(deleteInst) {
delete instance;
}
2022-08-30 14:02:58 +02:00
}
SECTION("Simple Serializable") {
2022-08-30 16:02:50 +02:00
util::DataWrapper* instance = &wrapper;
bool deleteInst = false;
REQUIRE(instance->isNull());
2022-08-30 14:02:58 +02:00
SimpleSerializable serializable;
2022-08-30 16:02:50 +02:00
SECTION("Setter") {
wrapper.setSerializable(serializable);
}
SECTION("Direct Construction") {
instance = new util::DataWrapper(serializable);
deleteInst = true;
}
REQUIRE(not instance->isNull());
REQUIRE(instance->type == util::DataTypes::SERIALIZABLE);
REQUIRE(instance->dataUnion.serializable == &serializable);
if(deleteInst) {
delete instance;
}
2022-08-30 14:02:58 +02:00
}
}