From 89435a5662320a7b77c359a15a3457ae666ae722 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 20 Nov 2023 17:53:47 -0500 Subject: Tests: Add dedicated test to cover cmUVHandlePtr types Move the case added by commit 70d88a5361 (cmUVHandlePtr: Add uv_idle_ptr, 2023-11-06) to a dedicated test. --- Tests/CMakeLib/CMakeLists.txt | 1 + Tests/CMakeLib/testUVHandlePtr.cxx | 36 ++++++++++++++++++++++++++++++++++++ Tests/CMakeLib/testUVRAII.cxx | 25 ------------------------- 3 files changed, 37 insertions(+), 25 deletions(-) create mode 100644 Tests/CMakeLib/testUVHandlePtr.cxx diff --git a/Tests/CMakeLib/CMakeLists.txt b/Tests/CMakeLib/CMakeLists.txt index 0e71cea..979d449 100644 --- a/Tests/CMakeLib/CMakeLists.txt +++ b/Tests/CMakeLib/CMakeLists.txt @@ -25,6 +25,7 @@ set(CMakeLib_TESTS testXMLParser.cxx testXMLSafe.cxx testFindPackageCommand.cxx + testUVHandlePtr.cxx testUVProcessChain.cxx testUVRAII.cxx testUVStreambuf.cxx diff --git a/Tests/CMakeLib/testUVHandlePtr.cxx b/Tests/CMakeLib/testUVHandlePtr.cxx new file mode 100644 index 0000000..5aab556 --- /dev/null +++ b/Tests/CMakeLib/testUVHandlePtr.cxx @@ -0,0 +1,36 @@ +#include + +#include + +#include "cmUVHandlePtr.h" + +static bool testIdle() +{ + bool idled = false; + + cm::uv_loop_ptr loop; + loop.init(); + + cm::uv_idle_ptr idle; + idle.init(*loop, &idled); + uv_idle_start(idle, [](uv_idle_t* handle) { + auto idledPtr = static_cast(handle->data); + *idledPtr = true; + uv_idle_stop(handle); + }); + uv_run(loop, UV_RUN_DEFAULT); + + if (!idled) { + std::cerr << "uv_idle_ptr did not trigger callback" << std::endl; + return false; + } + + return true; +} + +int testUVHandlePtr(int, char** const) +{ + bool passed = true; + passed = testIdle() && passed; + return passed ? 0 : -1; +} diff --git a/Tests/CMakeLib/testUVRAII.cxx b/Tests/CMakeLib/testUVRAII.cxx index 1b08778..9e79d5c 100644 --- a/Tests/CMakeLib/testUVRAII.cxx +++ b/Tests/CMakeLib/testUVRAII.cxx @@ -219,30 +219,6 @@ static bool testLoopDestructor() return true; } -static bool testIdle() -{ - bool idled = false; - - cm::uv_loop_ptr loop; - loop.init(); - - cm::uv_idle_ptr idle; - idle.init(*loop, &idled); - uv_idle_start(idle, [](uv_idle_t* handle) { - auto idledPtr = static_cast(handle->data); - *idledPtr = true; - uv_idle_stop(handle); - }); - uv_run(loop, UV_RUN_DEFAULT); - - if (!idled) { - std::cerr << "uv_idle_ptr did not trigger callback" << std::endl; - return false; - } - - return true; -} - int testUVRAII(int, char** const) { if (!testAsyncShutdown()) { @@ -255,6 +231,5 @@ int testUVRAII(int, char** const) passed = testAllMoves() && passed; passed = testLoopReset() && passed; passed = testLoopDestructor() && passed; - passed = testIdle() && passed; return passed ? 0 : -1; } -- cgit v0.12