mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-30 19:19:21 +00:00
[esp_timer]: created mock override component
This commit is contained in:
@@ -44,82 +44,6 @@ struct RefClock {
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE("ESPTimer null function", "[ESPTimer]")
|
||||
{
|
||||
TEST_THROW(ESPTimer(nullptr), ESPException);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPTimer empty std::function", "[ESPTimer]")
|
||||
{
|
||||
function<void()> nothing;
|
||||
TEST_THROW(ESPTimer(nothing, "test"), ESPException);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPTimer starting twice throws", "[ESPTimer]")
|
||||
{
|
||||
function<void()> timer_cb = [&]() { };
|
||||
|
||||
ESPTimer timer(timer_cb);
|
||||
|
||||
timer.start(chrono::microseconds(5000));
|
||||
|
||||
TEST_THROW(timer.start(chrono::microseconds(5000)), ESPException);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPTimer periodically starting twice throws", "[ESPTimer]")
|
||||
{
|
||||
function<void()> timer_cb = [&]() { };
|
||||
|
||||
ESPTimer timer(timer_cb);
|
||||
|
||||
timer.start_periodic(chrono::microseconds(5000));
|
||||
|
||||
TEST_THROW(timer.start_periodic(chrono::microseconds(5000)), ESPException);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPTimer stopping non-started timer throws", "[ESPTimer]")
|
||||
{
|
||||
function<void()> timer_cb = [&]() { };
|
||||
|
||||
ESPTimer timer(timer_cb);
|
||||
|
||||
TEST_THROW(timer.stop(), ESPException);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPTimer calls callback", "[ESPTimer]")
|
||||
{
|
||||
bool called = false;
|
||||
|
||||
function<void()> timer_cb = [&]() {
|
||||
called = true;
|
||||
};
|
||||
|
||||
ESPTimer timer(timer_cb);
|
||||
|
||||
timer.start(chrono::microseconds(5000));
|
||||
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
|
||||
TEST_ASSERT(called);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPTimer periodically calls callback", "[ESPTimer]")
|
||||
{
|
||||
size_t called = 0;
|
||||
|
||||
function<void()> timer_cb = [&]() {
|
||||
called++;
|
||||
};
|
||||
|
||||
ESPTimer timer(timer_cb);
|
||||
|
||||
timer.start_periodic(chrono::microseconds(2000));
|
||||
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
|
||||
TEST_ASSERT(called >= 4u);
|
||||
}
|
||||
|
||||
TEST_CASE("ESPTimer produces correct delay", "[ESPTimer]")
|
||||
{
|
||||
int64_t t_end;
|
||||
|
Reference in New Issue
Block a user