Various services improved (#110)

This commit is contained in:
Ken Van Hoeylandt
2024-12-06 23:16:29 +01:00
committed by GitHub
parent 36bb25deba
commit d52fe52d96
32 changed files with 771 additions and 636 deletions
+28 -9
View File
@@ -4,16 +4,26 @@
using namespace tt;
void increment_callback(void* context) {
auto* counter = (uint32_t*)context;
(*counter)++;
static uint32_t counter = 0;
static const uint32_t value_chacker_expected = 123;
void increment_callback(TT_UNUSED std::shared_ptr<void> context) {
counter++;
}
void value_checker(std::shared_ptr<void> context) {
auto value = std::static_pointer_cast<uint32_t>(context);
if (*value != value_chacker_expected) {
tt_crash_implementation();
}
}
TEST_CASE("dispatcher should not call callback if consume isn't called") {
counter = 0;
Dispatcher dispatcher;
uint32_t counter = 0;
dispatcher.dispatch(&increment_callback, &counter);
auto context = std::make_shared<uint32_t>();
dispatcher.dispatch(&increment_callback, std::move(context));
delay_ticks(10);
CHECK_EQ(counter, 0);
@@ -21,16 +31,25 @@ TEST_CASE("dispatcher should not call callback if consume isn't called") {
TEST_CASE("dispatcher should be able to dealloc when message is not consumed") {
auto* dispatcher = new Dispatcher();
uint32_t counter = 0;
dispatcher->dispatch(increment_callback, &counter);
auto context = std::make_shared<uint32_t>();
dispatcher->dispatch(increment_callback, std::move(context));
delete dispatcher;
}
TEST_CASE("dispatcher should call callback when consume is called") {
counter = 0;
Dispatcher dispatcher;
uint32_t counter = 0;
dispatcher.dispatch(increment_callback, &counter);
auto context = std::make_shared<uint32_t>();
dispatcher.dispatch(increment_callback, std::move(context));
dispatcher.consume(100);
CHECK_EQ(counter, 1);
}
TEST_CASE("message should be passed on correctly") {
Dispatcher dispatcher;
auto context = std::make_shared<uint32_t>(value_chacker_expected);
dispatcher.dispatch(value_checker, std::move(context));
dispatcher.consume(100);
}