Tactiliest/tests/tactility-core/dispatcher_test.cpp
Ken Van Hoeylandt b659d5b940
Added Dispatcher and fix sim (#54)
- Add dispatcher mechanism (a queue for function calls) and tests
- Added tests for MessageQueue
- Fix FreeRTOS config for simulator
- Explicit dependencies for touch-related libs, because minor version changes caused broken builds on CI.
2024-08-24 19:21:22 +02:00

39 lines
1.1 KiB
C++

#include "doctest.h"
#include "tactility_core.h"
#include "dispatcher.h"
void increment_callback(void* context) {
auto* counter = (uint32_t*)context;
(*counter)++;
}
TEST_CASE("dispatcher should not call callback if consume isn't called") {
Dispatcher* dispatcher = tt_dispatcher_alloc(10);
uint32_t counter = 0;
tt_dispatcher_dispatch(dispatcher, &increment_callback, &counter);
tt_delay_tick(10);
CHECK_EQ(counter, 0);
tt_dispatcher_free(dispatcher);
}
TEST_CASE("dispatcher should be able to dealloc when message is not consumed") {
Dispatcher* dispatcher = tt_dispatcher_alloc(10);
uint32_t counter = 0;
tt_dispatcher_dispatch(dispatcher, increment_callback, &counter);
tt_dispatcher_free(dispatcher);
}
TEST_CASE("dispatcher should call callback when consume is called") {
Dispatcher* dispatcher = tt_dispatcher_alloc(10);
uint32_t counter = 0;
tt_dispatcher_dispatch(dispatcher, increment_callback, &counter);
tt_dispatcher_consume(dispatcher, 100);
CHECK_EQ(counter, 1);
tt_dispatcher_free(dispatcher);
}