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
This commit is contained in:
committed by
GitHub
parent
d72852a6e2
commit
3f1bfee3f5
@@ -4,26 +4,10 @@
|
||||
|
||||
using namespace tt;
|
||||
|
||||
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("Test error");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("dispatcher should not call callback if consume isn't called") {
|
||||
counter = 0;
|
||||
int counter = 0;
|
||||
Dispatcher dispatcher;
|
||||
|
||||
auto context = std::make_shared<uint32_t>();
|
||||
dispatcher.dispatch(&increment_callback, std::move(context));
|
||||
dispatcher.dispatch([&counter]() { counter++; });
|
||||
kernel::delayTicks(10);
|
||||
|
||||
CHECK_EQ(counter, 0);
|
||||
@@ -32,24 +16,23 @@ 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();
|
||||
auto context = std::make_shared<uint32_t>();
|
||||
dispatcher->dispatch(increment_callback, std::move(context));
|
||||
dispatcher->dispatch([]() { /* NO-OP */ });
|
||||
delete dispatcher;
|
||||
}
|
||||
|
||||
TEST_CASE("dispatcher should call callback when consume is called") {
|
||||
counter = 0;
|
||||
int counter = 0;
|
||||
Dispatcher dispatcher;
|
||||
|
||||
auto context = std::make_shared<uint32_t>();
|
||||
dispatcher.dispatch(increment_callback, std::move(context));
|
||||
dispatcher.dispatch([&counter]() { counter++; });
|
||||
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.dispatch([]() { /* NO-OP */ });
|
||||
dispatcher.consume(100);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user