fsfw/unittests/util/testSeqCountProvider.cpp

36 lines
894 B
C++
Raw Normal View History

#include <catch2/catch_test_macros.hpp>
#include "fsfw/util/SeqCountProvider.h"
TEST_CASE("Seq Count Providers", "[util]") {
auto genericProviderTest = [](ProvidesSeqCountIF& provider, unsigned expectedWidth) {
CHECK(provider.get() == 0);
CHECK(provider.bitWidth() == expectedWidth);
CHECK(provider.getAndIncrement() == 0);
CHECK(provider.getAndIncrement() == 1);
CHECK(provider.get() == 2);
provider.increment();
provider.increment();
CHECK(provider.get() == 4);
};
{
SeqCountProviderU16 provider;
genericProviderTest(provider, 16);
}
{
SeqCountProviderU32 provider;
genericProviderTest(provider, 32);
}
{
SeqCountProviderU8 provider;
genericProviderTest(provider, 8);
for (unsigned i = 4; i < UINT8_MAX + 1; i++) {
provider.increment();
}
// Verify wrap-around.
CHECK(provider.get() == 0);
}
}