aboutsummaryrefslogtreecommitdiff
path: root/test/base/platform/unix/EventLoopTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/base/platform/unix/EventLoopTest.cpp')
-rw-r--r--test/base/platform/unix/EventLoopTest.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/base/platform/unix/EventLoopTest.cpp b/test/base/platform/unix/EventLoopTest.cpp
new file mode 100644
index 00000000..f5936b2a
--- /dev/null
+++ b/test/base/platform/unix/EventLoopTest.cpp
@@ -0,0 +1,24 @@
+#include "cru/base/platform/unix/EventLoop.h"
+
+#include <catch2/catch_test_macros.hpp>
+
+#include <poll.h>
+#include <chrono>
+
+TEST_CASE("UnixTimerFile Work", "[unix][time]") {
+ using namespace cru;
+ using namespace cru::platform::unix;
+
+ auto test_miliseconds = 300;
+ auto test_duration = std::chrono::milliseconds(test_miliseconds);
+ auto start = std::chrono::steady_clock::now();
+ REQUIRE((std::chrono::steady_clock::now() - start) < test_duration);
+
+ UnixTimerFile timer(test_duration);
+
+ struct pollfd fds[1];
+ fds[0].fd = timer.GetReadFd();
+ fds[0].events = POLLIN;
+ REQUIRE(::poll(fds, 1, test_miliseconds * 2) == 1);
+ REQUIRE((std::chrono::steady_clock::now() - start) > test_duration);
+}