From 8908f277d94ad9e0a1e04a2d9a8c69db955265e9 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 20 Nov 2023 18:10:39 -0500 Subject: Tests: Add dedicated test case for uv_timer_ptr --- Tests/CMakeLib/testUVHandlePtr.cxx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Tests/CMakeLib/testUVHandlePtr.cxx b/Tests/CMakeLib/testUVHandlePtr.cxx index f367047..02f8954 100644 --- a/Tests/CMakeLib/testUVHandlePtr.cxx +++ b/Tests/CMakeLib/testUVHandlePtr.cxx @@ -30,9 +30,36 @@ static bool testIdle() return true; } +static bool testTimer() +{ + bool timed = false; + + cm::uv_loop_ptr loop; + loop.init(); + + auto cb = [](uv_timer_t* handle) { + auto timedPtr = static_cast(handle->data); + *timedPtr = true; + uv_timer_stop(handle); + }; + + cm::uv_timer_ptr timer; + timer.init(*loop, &timed); + timer.start(cb, 10, 0); + uv_run(loop, UV_RUN_DEFAULT); + + if (!timed) { + std::cerr << "uv_timer_ptr did not trigger callback" << std::endl; + return false; + } + + return true; +} + int testUVHandlePtr(int, char** const) { bool passed = true; passed = testIdle() && passed; + passed = testTimer() && passed; return passed ? 0 : -1; } -- cgit v0.12