From b0a337774a7587b458428c9b8b0d06b060d2f215 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Tue, 22 Aug 2023 23:05:03 +0200 Subject: [PATCH] Unit test updates --- examples/eventloop.cpp | 6 ++++-- test/eventloop-monitor-test.cpp | 9 ++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/examples/eventloop.cpp b/examples/eventloop.cpp index 23749f71..4ce245f7 100644 --- a/examples/eventloop.cpp +++ b/examples/eventloop.cpp @@ -70,8 +70,10 @@ auto main() -> int tcsetattr (STDIN_FILENO, TCSAFLUSH, &new_term_io_settings); // Set file descriptor of stdin to non-blocking mode - int stdin_flags{fcntl(STDIN_FILENO, F_GETFL, 0)}; - (void)fcntl(STDIN_FILENO, F_SETFL, stdin_flags | O_NONBLOCK); + finalcut::FTermios::init(); + auto stdin_no = finalcut::FTermios::getStdIn(); + int stdin_flags{fcntl(stdin_no, F_GETFL, 0)}; + (void)fcntl(stdin_no, F_SETFL, stdin_flags | O_NONBLOCK); // Configure monitors timer1.init ( [] (const finalcut::Monitor*, short) diff --git a/test/eventloop-monitor-test.cpp b/test/eventloop-monitor-test.cpp index 1cdd177f..474f0fa2 100644 --- a/test/eventloop-monitor-test.cpp +++ b/test/eventloop-monitor-test.cpp @@ -284,6 +284,11 @@ void EventloopMonitorTest::setMonitorTest() //---------------------------------------------------------------------- void EventloopMonitorTest::IoMonitorTest() { + finalcut::FTermios::init(); + auto stdin_no = finalcut::FTermios::getStdIn(); + auto stdin_status_flags = fcntl(stdin_no, F_GETFL); + stdin_status_flags |= O_NONBLOCK; + fcntl (stdin_no, F_SETFL, stdin_status_flags); finalcut::EventLoop eloop{}; signal_handler = [this] (int) { @@ -303,13 +308,15 @@ void EventloopMonitorTest::IoMonitorTest() CPPUNIT_ASSERT ( buf == 'A' ); eloop.leave(); }; - io_monitor.init (STDIN_FILENO, POLLIN, callback_handler, nullptr); + io_monitor.init (stdin_no, POLLIN, callback_handler, nullptr); std::cout << "\n"; alarm(1); // Schedule a alarm after 1 seconds io_monitor.resume(); CPPUNIT_ASSERT ( eloop.run() == 0 ); signal(SIGALRM, SIG_DFL); signal_handler = [] (int) { }; // Do nothing + stdin_status_flags &= ~O_NONBLOCK; + fcntl (stdin_no, F_SETFL, stdin_status_flags); } //----------------------------------------------------------------------