Ken Van Hoeylandt 3f1bfee3f5
Various improvements (#264)
- Replace C function pointers with C++ `std::function` in `Thread`, `Timer` and `DispatcherThread`
- Rename `SystemEvent`-related functions
- WiFi: fix auto-connect when WiFi disconnects from bad signal
- WiFi: fix auto-connect when WiFi fails to auto-connect
- WiFi: implement disconnect() when tapping connected WiFi ap in WiFi management app
2025-03-30 21:59:31 +02:00

46 lines
1.1 KiB
C++

#include "doctest.h"
#include <Tactility/TactilityCore.h>
#include <Tactility/Timer.h>
using namespace tt;
TEST_CASE("TimerType::Periodic timers can be stopped and restarted") {
int counter = 0;
auto* timer = new Timer(Timer::Type::Periodic, [&counter]() { counter++; });
timer->start(1);
kernel::delayTicks(10);
timer->stop();
timer->start(1);
kernel::delayTicks(10);
timer->stop();
delete timer;
CHECK_GE(counter, 2);
}
TEST_CASE("TimerType::Periodic calls the callback periodically") {
int ticks_to_run = 10;
int counter = 0;
auto* timer = new Timer(Timer::Type::Periodic, [&counter]() { counter++; });
timer->start(1);
kernel::delayTicks(ticks_to_run);
timer->stop();
delete timer;
CHECK_EQ(counter, ticks_to_run);
}
TEST_CASE("restarting TimerType::Once timers calls the callback again") {
int counter = 0;
auto* timer = new Timer(Timer::Type::Once, [&counter]() { counter++; });
timer->start(1);
kernel::delayTicks(10);
timer->stop();
timer->start(1);
kernel::delayTicks(10);
timer->stop();
delete timer;
CHECK_EQ(counter, 2);
}