- 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.
39 lines
1.1 KiB
C++
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);
|
|
}
|