mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 10:53:17 +00:00
- 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
46 lines
1.1 KiB
C++
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);
|
|
}
|