103 lines
2.9 KiB
C++
103 lines
2.9 KiB
C++
|
|
#include <array>
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include "fsfw/subsystem/modes/ModeDefinitions.h"
|
|
|
|
TEST_CASE("Mode Definitions", "[mode]") {
|
|
ModeListEntry entry;
|
|
|
|
SECTION("Basic") {
|
|
entry.setMode(HasModesIF::MODE_OFF);
|
|
entry.setSubmode(2);
|
|
CHECK(entry.getMode() == HasModesIF::MODE_OFF);
|
|
CHECK(entry.getSubmode() == 2);
|
|
uint8_t mask;
|
|
CHECK(entry.submodesAllowed(&mask) == false);
|
|
}
|
|
|
|
SECTION("Inherit submode") {
|
|
entry.enableInheritSubmode();
|
|
CHECK(entry.inheritSubmode() == true);
|
|
entry.disableInheritSubmode();
|
|
CHECK(entry.inheritSubmode() == false);
|
|
}
|
|
|
|
SECTION("Allowed submode mask") {
|
|
entry.allowAllSubmodes();
|
|
uint8_t mask;
|
|
CHECK(entry.submodesAllowed(&mask) == true);
|
|
CHECK(mask == 0xff);
|
|
entry.enableSubmodeAllowed(0x32);
|
|
CHECK(entry.submodesAllowed(&mask) == true);
|
|
CHECK(mask == 0x32);
|
|
entry.disableSubmodeAllowed();
|
|
CHECK(entry.submodesAllowed(&mask) == false);
|
|
}
|
|
|
|
SECTION("Serialization nominal") {
|
|
std::array<uint8_t, 32> buf{};
|
|
entry.setObject(0x1f2f3f4f);
|
|
entry.setMode(HasModesIF::MODE_ON);
|
|
entry.setSubmode(2);
|
|
uint8_t* serPtr = buf.data();
|
|
size_t serLen = 0;
|
|
REQUIRE(entry.serialize(&serPtr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) ==
|
|
returnvalue::OK);
|
|
CHECK(buf[0] == 0x1f);
|
|
CHECK(buf[1] == 0x2f);
|
|
CHECK(buf[2] == 0x3f);
|
|
CHECK(buf[3] == 0x4f);
|
|
CHECK(buf[4] == 0);
|
|
CHECK(buf[5] == 0);
|
|
CHECK(buf[6] == 0);
|
|
CHECK(buf[7] == HasModesIF::MODE_ON);
|
|
CHECK(buf[8] == 2);
|
|
CHECK(buf[9] == 0);
|
|
}
|
|
|
|
SECTION("Serialization inherit submode") {
|
|
std::array<uint8_t, 32> buf{};
|
|
entry.setObject(0x1f2f3f4f);
|
|
entry.setMode(HasModesIF::MODE_ON);
|
|
entry.setSubmode(2);
|
|
entry.enableInheritSubmode();
|
|
uint8_t* serPtr = buf.data();
|
|
size_t serLen = 0;
|
|
REQUIRE(entry.serialize(&serPtr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) ==
|
|
returnvalue::OK);
|
|
CHECK(buf[0] == 0x1f);
|
|
CHECK(buf[1] == 0x2f);
|
|
CHECK(buf[2] == 0x3f);
|
|
CHECK(buf[3] == 0x4f);
|
|
CHECK(buf[4] == 0);
|
|
CHECK(buf[5] == 0);
|
|
CHECK(buf[6] == 0);
|
|
CHECK(buf[7] == HasModesIF::MODE_ON);
|
|
CHECK(buf[8] == 2);
|
|
CHECK(buf[9] == mode::SpecialSubmodeFlags::INHERIT);
|
|
}
|
|
|
|
SECTION("Serialization submode mask") {
|
|
std::array<uint8_t, 32> buf{};
|
|
entry.setObject(0x1f2f3f4f);
|
|
entry.setMode(HasModesIF::MODE_ON);
|
|
entry.setSubmode(2);
|
|
entry.enableSubmodeAllowed(0x1f);
|
|
uint8_t* serPtr = buf.data();
|
|
size_t serLen = 0;
|
|
REQUIRE(entry.serialize(&serPtr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) ==
|
|
returnvalue::OK);
|
|
CHECK(buf[0] == 0x1f);
|
|
CHECK(buf[1] == 0x2f);
|
|
CHECK(buf[2] == 0x3f);
|
|
CHECK(buf[3] == 0x4f);
|
|
CHECK(buf[4] == 0);
|
|
CHECK(buf[5] == 0);
|
|
CHECK(buf[6] == 0);
|
|
CHECK(buf[7] == HasModesIF::MODE_ON);
|
|
CHECK(buf[8] == 0x1f);
|
|
CHECK(buf[9] == mode::SpecialSubmodeFlags::ALLOWED_MASK);
|
|
}
|
|
}
|