Tactiliest/Tests/TactilityCore/DispatcherTest.cpp
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

39 lines
985 B
C++

#include "doctest.h"
#include <Tactility/TactilityCore.h>
#include <Tactility/Dispatcher.h>
using namespace tt;
TEST_CASE("dispatcher should not call callback if consume isn't called") {
int counter = 0;
Dispatcher dispatcher;
dispatcher.dispatch([&counter]() { counter++; });
kernel::delayTicks(10);
CHECK_EQ(counter, 0);
}
TEST_CASE("dispatcher should be able to dealloc when message is not consumed") {
auto* dispatcher = new Dispatcher();
auto context = std::make_shared<uint32_t>();
dispatcher->dispatch([]() { /* NO-OP */ });
delete dispatcher;
}
TEST_CASE("dispatcher should call callback when consume is called") {
int counter = 0;
Dispatcher dispatcher;
dispatcher.dispatch([&counter]() { counter++; });
dispatcher.consume(100);
CHECK_EQ(counter, 1);
}
TEST_CASE("message should be passed on correctly") {
Dispatcher dispatcher;
dispatcher.dispatch([]() { /* NO-OP */ });
dispatcher.consume(100);
}