Skip to content

Commit

Permalink
Unit test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gansm committed Aug 22, 2023
1 parent 11a78fe commit b0a3377
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions examples/eventloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion test/eventloop-monitor-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
}

//----------------------------------------------------------------------
Expand Down

0 comments on commit b0a3377

Please sign in to comment.