Skip to content

Commit

Permalink
* zeromq#207 The two testcases of loop.remove(raw_fd) in loop.handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Orekhov authored and Pavel Orekhov committed Jan 31, 2018
1 parent 25bd507 commit b6632bf
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/tests/test_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <boost/test/unit_test.hpp>
#include <thread>
#include <exception>
#include <unistd.h>

#define private public

Expand Down Expand Up @@ -256,5 +257,57 @@ BOOST_AUTO_TEST_CASE(remove_socket_in_handler)
BOOST_CHECK_EQUAL(2, test2);
}

BOOST_AUTO_TEST_CASE(remove_fd_in_handler)
{
zmqpp::context context;

zmqpp::loop loop;
auto end_loop = []() -> bool { return false; };

int pipefd[2];
BOOST_CHECK_EQUAL(0, pipe(pipefd));

int test1 = 0;
loop.add(pipefd[0], [&](){
test1 = 1;
loop.remove(pipefd[0]);
return true;
});

BOOST_CHECK_EQUAL(4, write(pipefd[1],"haha",4));
//BOOST_CHECK_EQUAL(0, close(pipefd[1]));

loop.add(std::chrono::milliseconds(100), 1, end_loop);
BOOST_CHECK_NO_THROW(loop.start());

BOOST_CHECK_EQUAL(1, test1);
}

BOOST_AUTO_TEST_CASE(remove_invalid_fd_in_handler)
{
zmqpp::context context;

zmqpp::loop loop;
auto end_loop = []() -> bool { return false; };

int pipefd[2];
BOOST_CHECK_EQUAL(0, pipe(pipefd));

int test1 = 0;
loop.add(pipefd[0], [&test1,&loop](){
test1 = 1;
loop.remove(STDIN_FILENO);
return true;
});

BOOST_CHECK_EQUAL(4, write(pipefd[1],"haha",4));
//BOOST_CHECK_EQUAL(0, close(pipefd[1]));

loop.add(std::chrono::milliseconds(100), 1, end_loop);
BOOST_CHECK_NO_THROW(loop.start());

BOOST_CHECK_EQUAL(1, test1);
}


BOOST_AUTO_TEST_SUITE_END()

0 comments on commit b6632bf

Please sign in to comment.