Revert "Modes: reusing submode for mode mask, more unittests"

This reverts commit f0bddfcb21.
This commit is contained in:
Robin Müller 2023-03-10 14:50:16 +01:00
parent c162acb7df
commit 55f6825a03
2 changed files with 11 additions and 60 deletions

View File

@ -21,6 +21,7 @@ class ModeListEntry : public SerialLinkedListAdapter<SerializeIF>,
SerializeElement<uint32_t> value2 = 0;
SerializeElement<uint8_t> value3 = 0;
SerializeElement<uint8_t> value4 = 0;
SerializeElement<uint8_t> value5 = 0;
ModeListEntry(const ModeListEntry& other)
: SerialLinkedListAdapter(), LinkedElement<ModeListEntry>(this) {
@ -28,6 +29,7 @@ class ModeListEntry : public SerialLinkedListAdapter<SerializeIF>,
value2.entry = other.value2.entry;
value3.entry = other.value3.entry;
value4.entry = other.value4.entry;
value5.entry = other.value5.entry;
setLinks();
}
@ -36,6 +38,7 @@ class ModeListEntry : public SerialLinkedListAdapter<SerializeIF>,
this->value2.entry = other.value2.entry;
this->value3.entry = other.value3.entry;
this->value4.entry = other.value4.entry;
this->value5.entry = other.value5.entry;
return *this;
}
@ -44,6 +47,7 @@ class ModeListEntry : public SerialLinkedListAdapter<SerializeIF>,
value1.setNext(&value2);
value2.setNext(&value3);
value3.setNext(&value4);
value4.setNext(&value5);
}
// for Sequences
@ -80,7 +84,7 @@ class ModeListEntry : public SerialLinkedListAdapter<SerializeIF>,
bool submodesAllowed = (value4.entry & mode::SpecialSubmodeFlags::ALLOWED_MASK) ==
mode::SpecialSubmodeFlags::ALLOWED_MASK;
if (submodesAllowed and mask != nullptr) {
*mask = value3.entry;
*mask = value5.entry;
}
return submodesAllowed;
}
@ -109,14 +113,14 @@ class ModeListEntry : public SerialLinkedListAdapter<SerializeIF>,
*/
void enableSubmodeAllowed(uint8_t mask) {
value4.entry |= mode::SpecialSubmodeFlags::ALLOWED_MASK;
value3.entry = mask;
value5.entry = mask;
}
/**
* Enforce the equality of submodes for mode checks. This is the default.
*/
void disableSubmodeAllowed() {
value4.entry &= ~mode::SpecialSubmodeFlags::ALLOWED_MASK;
value3.entry = 0;
value5.entry = 0;
}
};

View File

@ -16,73 +16,19 @@ TEST_CASE("Mode Definitions", "[mode]") {
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") {
SECTION("Serialization") {
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;
@ -96,7 +42,8 @@ TEST_CASE("Mode Definitions", "[mode]") {
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);
CHECK(buf[8] == 2);
CHECK(buf[9] == (mode::SpecialSubmodeFlags::ALLOWED_MASK | mode::SpecialSubmodeFlags::INHERIT));
CHECK(buf[10] == 0x1f);
}
}