diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-09-09 01:43:13 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-09-09 01:43:13 +0800 |
commit | 429905d4e893f91618908773166ba867970c9a17 (patch) | |
tree | f87fc7a6ed6ce345a6795d059426d9a60f50c3c3 /test/base/platform/unix/EventLoopTest.cpp | |
parent | 37d9a034013b4245a50c0d748dc83d2c3d136210 (diff) | |
download | cru-429905d4e893f91618908773166ba867970c9a17.tar.gz cru-429905d4e893f91618908773166ba867970c9a17.tar.bz2 cru-429905d4e893f91618908773166ba867970c9a17.zip |
Implement SetPoll of event loop.
Diffstat (limited to 'test/base/platform/unix/EventLoopTest.cpp')
-rw-r--r-- | test/base/platform/unix/EventLoopTest.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/test/base/platform/unix/EventLoopTest.cpp b/test/base/platform/unix/EventLoopTest.cpp index 5d4dbcf2..3a9e3281 100644 --- a/test/base/platform/unix/EventLoopTest.cpp +++ b/test/base/platform/unix/EventLoopTest.cpp @@ -25,7 +25,7 @@ TEST_CASE("UnixTimerFile Work", "[unix][time]") { REQUIRE(delay < std::chrono::milliseconds(500)); } -TEST_CASE("UnixEventLoop Work", "[unix][time]") { +TEST_CASE("UnixEventLoop Timer Work", "[unix][time]") { using namespace cru; using namespace cru::platform::unix; @@ -78,3 +78,33 @@ TEST_CASE("UnixEventLoop Work", "[unix][time]") { REQUIRE(exit_code == 0); REQUIRE(counter == 2); } + +TEST_CASE("UnixEventLoop Poll Work", "[unix][time]") { + using namespace cru; + using namespace cru::platform::unix; + + UnixEventLoop loop; + + auto test_pipe = OpenUniDirectionalPipe(); + + bool triggered = false; + + loop.SetPoll(test_pipe.read, POLLIN, [&loop, &triggered](auto revent) { + REQUIRE(revent & POLLIN); + REQUIRE(!triggered); + triggered = true; + loop.RequestQuit(); + }); + + loop.SetTimeout( + [&test_pipe] { + auto buffer = ""; + test_pipe.write.Write(buffer, 1); + }, + std::chrono::milliseconds(300)); + + auto exit_code = loop.Run(); + + REQUIRE(exit_code == 0); + REQUIRE(triggered); +} |