forked from zeromq/cppzmq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: no test case for zmq::monitor_t::init
Solution: added test case
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <gtest/gtest.h> | ||
#include <gmock/gmock.h> | ||
#include <zmq.hpp> | ||
|
||
class mock_monitor_t : public zmq::monitor_t | ||
{ | ||
public: | ||
MOCK_METHOD2(on_event_connect_delayed, void(const zmq_event_t &, const char *)); | ||
MOCK_METHOD2(on_event_connected, void(const zmq_event_t &, const char *)); | ||
}; | ||
|
||
TEST(monitor, create_destroy) | ||
{ | ||
zmq::monitor_t monitor; | ||
} | ||
|
||
TEST(monitor, init_check) | ||
{ | ||
zmq::context_t ctx; | ||
zmq::socket_t bind_socket(ctx, ZMQ_DEALER); | ||
|
||
bind_socket.bind("tcp://127.0.0.1:*"); | ||
char endpoint[255]; | ||
size_t endpoint_len = sizeof(endpoint); | ||
bind_socket.getsockopt(ZMQ_LAST_ENDPOINT, &endpoint, &endpoint_len); | ||
|
||
zmq::socket_t connect_socket(ctx, ZMQ_DEALER); | ||
|
||
mock_monitor_t monitor; | ||
EXPECT_CALL(monitor, on_event_connect_delayed(testing::_, testing::_)) | ||
.Times(testing::AtLeast(1)); | ||
EXPECT_CALL(monitor, on_event_connected(testing::_, testing::_)) | ||
.Times(testing::AtLeast(1)); | ||
|
||
monitor.init(connect_socket, "inproc://foo"); | ||
|
||
ASSERT_FALSE(monitor.check_event(0)); | ||
connect_socket.connect(endpoint); | ||
|
||
while (monitor.check_event(100)) { | ||
} | ||
} |