2021-09-27 21:53:27 +02:00
|
|
|
#include <fsfw/timemanager/Countdown.h>
|
2022-02-02 10:29:30 +01:00
|
|
|
|
2021-09-27 21:53:27 +02:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
2023-03-03 14:54:52 +01:00
|
|
|
#include <chrono>
|
|
|
|
#include <thread>
|
2021-09-27 21:53:27 +02:00
|
|
|
|
2022-07-18 11:58:55 +02:00
|
|
|
#include "CatchDefinitions.h"
|
2021-09-27 21:53:27 +02:00
|
|
|
|
2023-03-03 14:54:52 +01:00
|
|
|
static constexpr bool TEST_LONGER_CD = false;
|
2022-02-02 10:29:30 +01:00
|
|
|
TEST_CASE("Countdown Tests", "[TestCountdown]") {
|
|
|
|
INFO("Countdown Tests");
|
|
|
|
Countdown count(20);
|
2023-03-03 14:54:52 +01:00
|
|
|
REQUIRE(count.getTimeoutMs() == 20);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(count.setTimeout(100) == static_cast<uint16_t>(returnvalue::OK));
|
2023-03-03 14:54:52 +01:00
|
|
|
REQUIRE(count.getTimeoutMs() == 100);
|
2022-08-16 01:08:26 +02:00
|
|
|
REQUIRE(count.setTimeout(150) == static_cast<uint16_t>(returnvalue::OK));
|
2022-02-02 10:29:30 +01:00
|
|
|
REQUIRE(count.isBusy());
|
|
|
|
REQUIRE(not count.hasTimedOut());
|
|
|
|
uint32_t number = count.getRemainingMillis();
|
|
|
|
REQUIRE(number > 0);
|
|
|
|
bool blocked = false;
|
|
|
|
while (not count.hasTimedOut()) {
|
|
|
|
blocked = true;
|
|
|
|
};
|
|
|
|
REQUIRE(blocked);
|
|
|
|
number = count.getRemainingMillis();
|
|
|
|
REQUIRE(number == 0);
|
|
|
|
count.resetTimer();
|
|
|
|
REQUIRE(not count.hasTimedOut());
|
|
|
|
REQUIRE(count.isBusy());
|
2023-03-03 14:54:52 +01:00
|
|
|
count.setTimeout(100);
|
|
|
|
REQUIRE(not count.hasTimedOut());
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
|
|
|
REQUIRE(not count.hasTimedOut());
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
|
|
|
REQUIRE(count.hasTimedOut());
|
|
|
|
|
|
|
|
// Takes longer, disabled by default
|
|
|
|
if (TEST_LONGER_CD) {
|
|
|
|
count.setTimeout(2500);
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
|
|
|
REQUIRE(not count.hasTimedOut());
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
|
|
|
|
REQUIRE(count.hasTimedOut());
|
|
|
|
}
|
2021-09-27 21:53:27 +02:00
|
|
|
}
|